> ## 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.

# GitHub egress

> Let git and the GitHub API in a sandbox work through the Tilde gateway, which adds the credential and checks every push, so no GitHub token enters the VM.

GitHub egress lets processes in a sandbox clone, fetch, and push to GitHub, and call the GitHub API, with no GitHub token in the VM. Requests go through the Tilde gateway. The gateway checks each one against the blueprint's **egress grant**, adds the GitHub credential from a [connection](https://trytilde.ai/docs/connections.md), and records it in the agent's trace.

Use it when an agent should work on your repositories in a [sandbox](https://trytilde.ai/docs/sandboxes/overview.md): open a branch, push commits, and open a pull request. The agent can push only to the branches you grant, and never to the default branch.

## Before you start

* A [sandbox blueprint](https://trytilde.ai/docs/sandboxes/setup.md#create-a-blueprint), given to an agent.
* An image whose sandbox process runs as root, such as a [Tilde sandbox image](https://trytilde.ai/docs/sandboxes/setup.md#tilde-sandbox-images). The process writes `/etc/gitconfig` to point git at the gateway.
* A GitHub connection: a **GitHub App**, **Personal access token**, or **OAuth app** connection that is ready and not personal.

> [!TIP]
>
> Prefer a **GitHub App** connection. For each request, Tilde mints an installation token limited to the grant's repositories and permissions. A personal access token or OAuth token cannot be narrowed, so only the gateway's checks limit it.

## Grant egress

**1. Open the blueprint's Egress tab**

Open the blueprint in **Sandboxes**, select **Egress**, and select **Add egress**.

**2. Choose the connection and a slug**

Choose the GitHub **Connection**. The **Slug** names the grant, such as `github`. It appears in the grant's route and in `TILDE_EGRESS_GITHUB_URL`.

**3. Narrow it**

Choose the **Repositories**, the branches pushes may update under **Push** › **Branches**, and whether to allow **Pull requests**. See [What a grant allows](#what-a-grant-allows).

**4. Enable it**

Switch on **Enabled**, and select **Save**. A grant is off until you enable it.

Grant changes apply to the next request. Toggle **Enabled** in the list to pause a grant, or delete it to cut sandboxes off.

## Try it

Ask the agent to make a change and open a pull request. Inside the sandbox, git works unchanged:

```bash theme={"system"}
git clone https://github.com/acme/api.git
cd api
git switch -c factory/fix-login
git commit -am "Fix the login redirect"
git push origin factory/fix-login
```

Call the GitHub REST API at `$GITHUB_API_URL`, with `$GITHUB_TOKEN`:

```bash theme={"system"}
curl -s -X POST "$GITHUB_API_URL/repos/acme/api/pulls" \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  -d '{"title": "Fix the login redirect", "head": "factory/fix-login", "base": "main"}'
```

In the agent's [trace](https://trytilde.ai/docs/traces.md), each request is a `sandbox.egress` span under the invocation, with the repository, the decision, and the reason for any refusal.

## What the sandbox sees

When the sandbox connects, `tilde sandbox connect` wires every shell for the blueprint's enabled grants:

* **Git.** `/etc/gitconfig` rewrites `https://github.com/` to the gateway route, and makes [`tilde sandbox credential`](https://trytilde.ai/docs/sandboxes/cli#tilde-sandbox-credential) git's credential helper for the gateway.
* **`GITHUB_API_URL`.** The gateway route for the GitHub API.
* **`GITHUB_TOKEN`.** The sandbox's **egress token**. It is not a GitHub token.
* **`TILDE_EGRESS_<SLUG>_URL`.** The grant's route, such as `TILDE_EGRESS_GITHUB_URL`.

The egress token works only at the gateway, only for the blueprint's enabled grants, and only while the sandbox exists. Every process in the VM, and the agent, can read it, which is why it carries no GitHub access of its own.

> [!NOTE]
>
> The GitHub CLI, `gh`, calls `api.github.com` directly, not `$GITHUB_API_URL`, so its API calls do not go through egress. Use `curl` or an API client you point at `$GITHUB_API_URL`. Git commands work either way.

## What a grant allows

Every GitHub grant allows only git fetch and push, and REST calls that read a repository or work on pull requests, reviews, and issue comments. The gateway always refuses organization endpoints, repository deletion, and repository settings such as secrets, webhooks, deploy keys, collaborators, and branch protection.

The grant narrows this further:

| Setting | What it does |
| - | - |
| **Repositories** | The repositories sandboxes may reach. Empty: every repository the connection can reach. |
| **Push** › **Branches** | Branch patterns pushes may create and update. `*` matches within one path segment, so `factory/*` matches `factory/fix-login`. Defaults to `factory/*`. Empty: no pushes. |
| **Pull requests** | Lets sandboxes open and update pull requests, and comment on them. On by default. Off: REST calls are read-only. |

A push is refused if it would:

* Update a branch that is not granted, or any tag.
* Delete a branch.
* Force-push, or rewrite history in any other way.
* Update the repository's default branch, even when a pattern matches it.

Pushes are capped at 100 MiB, and signed pushes are not supported.

## When a request is refused

Git and `curl` fail with HTTP `403`. Open the agent's trace, and read the `sandbox.egress` span's reason, such as `Pushing to refs/heads/main is not granted`. To allow the request, change the grant. For example, add the branch pattern, or the repository.

## Who can manage egress

Egress grants belong to their blueprint, and follow its [access](https://trytilde.ai/docs/sandboxes/setup.md#who-can-manage-sandboxes). Adding a grant also needs `view` on the connection.


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