> ## Documentation Index
> Fetch the complete documentation index at: https://trytilde.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Short-lived credentials from blueprint tools

> Give processes in a sandbox short-lived, narrowly scoped credentials, minted on demand by your own tool server, using a Git credential helper as the worked example.

Credential vending gives a process in a sandbox a credential only at the moment it needs one. A tool on your own [Tilde tool server](https://trytilde.ai/docs/tools/overview.md#tilde-tool-servers) mints a short-lived, narrowly scoped credential, and the process fetches it through the blueprint. Nothing in the VM holds a long-lived secret, and every call is in the agent's trace.

Use it in any edition, for systems that [GitHub egress](https://trytilde.ai/docs/sandboxes/github-egress.md) does not cover: other Git hosts, package registries, cloud CLIs, and databases. In Tilde Cloud and Tilde Enterprise, use GitHub egress for GitHub. It keeps the credential out of the VM entirely.

This guide builds a Git credential helper in three steps: write the tool, switch it on for the blueprint, and point git at it.

## 1. Write the tool

The tool receives git's request, `protocol`, `host`, and `path`, and returns `username` and `password`. This one mints a GitHub App installation token for one repository on an allowlist. GitHub expires it within an hour.

```typescript tool-server.ts theme={"system"}
import * as z from "zod";
import { createAppAuth } from "@octokit/auth-app";
import { createToolHost, defineTool } from "@trytilde/sdk/tool-host";

const allowed = new Set(["acme/api", "acme/web"]);

const github = createAppAuth({
  appId: process.env.GITHUB_APP_ID!,
  privateKey: process.env.GITHUB_APP_PRIVATE_KEY!,
  installationId: Number(process.env.GITHUB_APP_INSTALLATION_ID),
});

// Dials out with TILDE_TOOL_HOST_TOKEN. Nothing calls this process.
createToolHost({
  tools: {
    git_credentials: defineTool({
      description: "Issue a short-lived Git credential for one allowed GitHub repository.",
      summary: "Issued a Git credential",
      inputSchema: z.object({ protocol: z.string(), host: z.string(), path: z.string().optional() }),
      run: async ({ protocol, host, path }, ctx) => {
        // Only processes inside a sandbox get credentials, never an agent directly.
        if (!ctx.sandboxId) throw new Error("Git credentials are only issued to sandboxes");
        const repository = path?.replace(/\.git$/, "") ?? "";
        if (protocol !== "https" || host !== "github.com" || !allowed.has(repository)) {
          throw new Error(`No credential for ${host}/${repository}`);
        }
        const { token } = await github({
          type: "installation",
          repositoryNames: [repository.split("/")[1]],
          permissions: { contents: "write" },
        });
        return { username: "x-access-token", password: token };
      },
    }),
  },
});
```

Run the server with `TILDE_TOOL_HOST_TOKEN` set, and keep the private key on the server only. See [Add a Tilde tool server](https://trytilde.ai/docs/tools/management.md#add-a-tilde-tool-server). The Python SDK provides the same API in `tilde.tool_hosts`.

When a process in a sandbox calls a tool, `ctx.sandboxId` names the sandbox. `ctx.agentId` and `ctx.threadId` name the agent and thread it was launched for, when the [reuse mode](https://trytilde.ai/docs/sandboxes/reuse-modes.md) ties it to one. In Python, they are `context.sandbox_id`, `context.agent_id`, and `context.thread_id`. Use them to scope credentials further.

## 2. Switch the tool on for the blueprint

Open the blueprint in **Sandboxes**, and select **Tools**. Add the tool server, and switch on `git_credentials`. Processes call it by the source's slug and the tool name. This guide assumes the slug `creds`, so the tool is `creds.git_credentials`.

Do not give this tool to the agent. Git fetches the credential itself when it needs one.

## 3. Point git at it

Git runs a credential helper with `get`, and writes the request to its standard input as `key=value` lines. This helper calls the tool through the [local API](https://trytilde.ai/docs/sandboxes/cli.md#local-api), and prints the lines git expects.

```sh git-credential-tilde theme={"system"}
#!/bin/sh
set -eu
[ "${1:-}" = get ] || exit 0   # Nothing to store or erase.

protocol= host= path=
while IFS='=' read -r key value; do
  [ -n "$key" ] || break
  case $key in protocol) protocol=$value ;; host) host=$value ;; path) path=$value ;; esac
done

# The operation header nests this call under the sandbox.exec that ran git, in the trace.
jq -cn --arg protocol "$protocol" --arg host "$host" --arg path "$path" \
    '{protocol: $protocol, host: $host, path: $path}' \
  | curl -fsS -X POST http://127.0.0.1:4790/v1/tools/creds.git_credentials \
      -H 'content-type: application/json' \
      -H "x-tilde-sandbox-operation: ${TILDE_SANDBOX_OPERATION:-}" --data @- \
  | jq -r '"username=\(.username)\npassword=\(.password)"'
```

Install it in your image, and point git at it. `credential.useHttpPath` makes git send the repository path, which the tool needs.

```dockerfile Dockerfile theme={"system"}
FROM ghcr.io/trytilde/sandbox-debian-node:<version>

COPY git-credential-tilde /usr/local/bin/git-credential-tilde
RUN chmod 755 /usr/local/bin/git-credential-tilde \
 && git config --system credential.helper /usr/local/bin/git-credential-tilde \
 && git config --system credential.useHttpPath true
```

Ask the agent to clone an allowed repository and push. In the agent's [trace](https://trytilde.ai/docs/traces.md), each credential request is an `execute_tool creds.git_credentials` span under the `sandbox.exec` that ran git. A repository off the allowlist fails with the tool's error.

> [!WARNING]
>
> A tool's output is recorded in the trace like any other tool call, so the token appears there. Vend only short-lived credentials scoped to what the process needs, and restrict who can read traces.

## Other systems

The same pattern works for anything a process in the sandbox must reach:

* **Package registries.** Return a short-lived npm, PyPI, or container registry token, and fetch it from a credential helper.
* **Cloud CLIs.** Return temporary credentials, such as AWS STS credentials for one role, through the CLI's credential process setting.
* **Databases.** Return a short-lived database user or IAM authentication token.

If the tool server can do the work itself, return the result instead of a credential. The credential then never enters the sandbox.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.