diff --git a/apps/server/src/sandbox/SandboxProvisioner.test.ts b/apps/server/src/sandbox/SandboxProvisioner.test.ts
index 4d9a450d40f2a..f18da45125097 100644
--- a/apps/server/src/sandbox/SandboxProvisioner.test.ts
+++ b/apps/server/src/sandbox/SandboxProvisioner.test.ts
@@ -7634,11 +7634,13 @@ describe("SandboxProvisioner per-thread launches", () => {
"local wasn't copied. Runs a program on this machine, so it can't be copied.",
]);
- // An hour-long token for this repository alone, kept as a server secret.
+ // An hour-long token for every repository the installation covers, found through this
+ // one and kept as a server secret.
const tokenRequest = services.state.calls.find((call) =>
call.url.endsWith("/access_tokens"),
);
- expect(tokenRequest?.body).toEqual({ repositories: ["hello"] });
+ expect(tokenRequest).toBeDefined();
+ expect(tokenRequest?.body ?? {}).not.toHaveProperty("repositories");
const record = repository.records.get(instanceId)!;
expect(record.githubApp).toMatchObject({ installationId: 7, repository: "octo/hello" });
expect(new TextDecoder().decode(secrets.values.get(record.githubApp!.secret))).toBe(
@@ -8038,6 +8040,10 @@ describe("SandboxProvisioner per-thread launches", () => {
"POST https://api.github.com/app/installations/7/access_tokens",
"DELETE https://api.github.com/installation/token",
]);
+ // The renewed token covers the whole installation too, and the record keeps the
+ // repository it finds the installation through.
+ expect(services.state.calls[0]?.body ?? {}).not.toHaveProperty("repositories");
+ expect(renewed.githubApp?.repository).toBe("octo/hello");
expect(services.state.calls[1]?.auth).toBe("Bearer ghs_OLD");
expect(secretsFileWith(fake, "T3_GITHUB_TOKEN")).toContain("ghs_SANDBOX1");
// A stopped sandbox is not woken for it.
diff --git a/apps/server/src/sandbox/SandboxProvisioner.ts b/apps/server/src/sandbox/SandboxProvisioner.ts
index 4966d5ecba041..ff4e1b23f02ce 100644
--- a/apps/server/src/sandbox/SandboxProvisioner.ts
+++ b/apps/server/src/sandbox/SandboxProvisioner.ts
@@ -832,7 +832,9 @@ const make = Effect.gen(function* () {
const githubInstallUrl = (slug: string) =>
`https://github.com/apps/${encodeURIComponent(slug)}/installations/new`;
- // Null when the app is not installed on the repository, which only the user can change.
+ // Finds the installation through the sandbox's repository; the token then covers every repository
+ // that installation does. Null when the app is not installed on the repository, which only the
+ // user can change.
const mintGithubToken = Effect.fn("SandboxProvisioner.mintGithubToken")(function* (
app: GithubAppCredentials,
repository: { readonly owner: string; readonly name: string },
@@ -841,11 +843,7 @@ const make = Effect.gen(function* () {
const installationId =
knownInstallation ?? (yield* githubAppApi.repositoryInstallation(app, repository));
if (installationId === null) return null;
- const minted = yield* githubAppApi.createInstallationToken(
- app,
- installationId,
- repository.name,
- );
+ const minted = yield* githubAppApi.createInstallationToken(app, installationId);
const secret = `sandbox-github-token-${yield* secureRandom.uuidV4()}`;
yield* secrets.set(secret, new TextEncoder().encode(Redacted.value(minted.token))).pipe(
Effect.tapError(() => githubAppApi.revokeInstallationToken(minted.token).pipe(Effect.ignore)),
diff --git a/apps/server/src/sandbox/githubAppApi.ts b/apps/server/src/sandbox/githubAppApi.ts
index 9a7114d6e5096..c8ab739e315d0 100644
--- a/apps/server/src/sandbox/githubAppApi.ts
+++ b/apps/server/src/sandbox/githubAppApi.ts
@@ -143,21 +143,21 @@ export const makeGithubAppApi = Effect.gen(function* () {
);
});
- /** An hour-long token for one repository of the installation, with the app's permissions. */
+ /**
+ * An hour-long token with the app's permissions on every repository the installation covers. The
+ * user picks those repositories in the installation's settings on GitHub, so an agent can work on
+ * more than the sandbox's own repository.
+ */
const createInstallationToken = Effect.fn("GithubAppApi.createInstallationToken")(function* (
app: GithubAppCredentials,
installationId: number,
- repositoryName: string,
) {
const jwt = yield* appJwt(app);
const body = yield* send(
"making a token for the sandbox",
HttpClientRequest.post(
`${GITHUB_API}/app/installations/${installationId}/access_tokens`,
- ).pipe(
- HttpClientRequest.bearerToken(Redacted.value(jwt)),
- HttpClientRequest.bodyJsonUnsafe({ repositories: [repositoryName] }),
- ),
+ ).pipe(HttpClientRequest.bearerToken(Redacted.value(jwt))),
HttpClientResponse.schemaBodyJson(InstallationToken),
);
return { token: Redacted.make(body.token), expiresAt: body.expires_at };
diff --git a/apps/server/src/sandbox/githubAppManifestRoute.test.ts b/apps/server/src/sandbox/githubAppManifestRoute.test.ts
index f3f0acb25ce89..d7ca8b0fc2e91 100644
--- a/apps/server/src/sandbox/githubAppManifestRoute.test.ts
+++ b/apps/server/src/sandbox/githubAppManifestRoute.test.ts
@@ -54,7 +54,12 @@ describe("GitHub App manifest page", () => {
name: "T3 Code sandboxes",
public: false,
redirect_url: SANDBOX_GITHUB_APP_PASTE_REDIRECT_URL,
- default_permissions: { contents: "write", pull_requests: "write", metadata: "read" },
+ default_permissions: {
+ contents: "write",
+ pull_requests: "write",
+ metadata: "read",
+ workflows: "write",
+ },
});
expect(body).toContain('');
});
diff --git a/apps/web/src/components/settings/SandboxAccessRows.browser.test.tsx b/apps/web/src/components/settings/SandboxAccessRows.browser.test.tsx
index 9975a745ffc51..b9bc83a3eed8e 100644
--- a/apps/web/src/components/settings/SandboxAccessRows.browser.test.tsx
+++ b/apps/web/src/components/settings/SandboxAccessRows.browser.test.tsx
@@ -208,6 +208,7 @@ describe("SandboxAccessRows", () => {
checks: "read",
statuses: "read",
actions: "read",
+ workflows: "write",
},
}),
},
diff --git a/apps/web/src/components/settings/SandboxAccessRows.tsx b/apps/web/src/components/settings/SandboxAccessRows.tsx
index 2cfcbe2369c39..a4ee7b4eb8d5c 100644
--- a/apps/web/src/components/settings/SandboxAccessRows.tsx
+++ b/apps/web/src/components/settings/SandboxAccessRows.tsx
@@ -198,7 +198,7 @@ const INTEGRATIONS: Record<
anchor: "sandbox-github-app",
name: "GitHub App",
about:
- "Gives each sandbox an hour-long token for its own repository, revoked when it's deleted. Create the app once, then install it on the repositories sandboxes may use.",
+ "Gives each sandbox an hour-long token for every repository the app is installed on, revoked when it's deleted. Create the app once, then install it on the repositories sandboxes may use.",
docs: { href: GITHUB_APP_DOCS, label: "How it works" },
},
northflank: {
diff --git a/apps/web/src/components/settings/SandboxToolingFields.tsx b/apps/web/src/components/settings/SandboxToolingFields.tsx
index f205b63a79b33..50592d74f7b2c 100644
--- a/apps/web/src/components/settings/SandboxToolingFields.tsx
+++ b/apps/web/src/components/settings/SandboxToolingFields.tsx
@@ -199,7 +199,7 @@ export function SandboxAgentToolingFields({
draft.githubMode === "app"
? host?.githubApp === undefined
? "The GitHub App isn't connected on this machine"
- : `A token for its repository only, as ${host.githubApp.slug}`
+ : `A token for the repositories ${host.githubApp.slug} is installed on`
: draft.githubMode === "legacy"
? host?.github === true
? "This machine's token, not revoked on delete"
diff --git a/docs/internals/sandbox-environments.md b/docs/internals/sandbox-environments.md
index 1681a4eec1b57..953e6e05e39fe 100644
--- a/docs/internals/sandbox-environments.md
+++ b/docs/internals/sandbox-environments.md
@@ -240,6 +240,17 @@ server except into the sandbox.
the machine, and the environment only when nothing is left in it, since it is the only way to
find a fork again. The sweep's abandoned-launch delete never touches forks. The driver hides
`t3-sandbox-*` environments from `listEnvironments`, so they never show as credential choices.
+- **A GitHub App token covers the whole installation.** `mintGithubToken` finds the installation
+ through the sandbox's repository (`GET /repos/{owner}/{repo}/installation`; a 404 is "not
+ installed", a launch warning with the install link), then mints with no `repositories` in the
+ body, so the token reaches every repository the user installed the app on and an agent can push
+ to a second repository from one sandbox. The record keeps `{ installationId, repository, secret,
+ expiresAt }`; the sweep renews a running sandbox's token 20 minutes before it expires (and a
+ resume renews it at once) with the known installation id, writes it with the login script, then
+ revokes the old one. The manifest
+ asks for `workflows: "write"` because GitHub refuses a push that touches `.github/workflows/`
+ without it; an app made from an older manifest needs it added on GitHub and approved by each
+ installation.
- **A Railway token belongs to one sandbox.** The saved workspace token mints
`t3-sandbox-` in its workspace ([`railwayApi.ts`](../../apps/server/src/sandbox/railwayApi.ts)).
Railway returns only the token's value, so every revoke lists the workspace's tokens and deletes
diff --git a/docs/user/remote-access.md b/docs/user/remote-access.md
index 997eea9d5ac17..d8700385e2425 100644
--- a/docs/user/remote-access.md
+++ b/docs/user/remote-access.md
@@ -37,7 +37,8 @@ With a hub, **Pi** also installs the [Pi agent](./providers-pi.md)
in each sandbox with the hub's non-Claude models, on that same key, and **Start new chats on** can
make new chats on the config start on Pi with one of them instead of Claude.
**GitHub** lets `gh` and `git` in each sandbox clone private repositories and push, with a
-token from the GitHub App or this machine's own. Without it a sandbox can clone public repositories only.
+token from the [GitHub App](#github-in-a-sandbox) or this machine's own. Without it a sandbox can
+clone public repositories only.
[**Let the agent use Boat**](#let-the-agent-use-boat) signs the `boat` CLI in on each Boat sandbox
with a key scoped to it. T3 Code also
installs git, the GitHub CLI, and Claude Code when the provider's image lacks them; sign Codex in
@@ -230,6 +231,30 @@ have been idle for the config's **Stop when idle** time (30 minutes by default).
up, the setup card or the resume says so, and that sandbox stops at its running limit as before.
- On a Boat trial the idle time is capped at two hours, Boat's longest trial auto-stop.
+### GitHub in a sandbox
+
+With **Sign in with → GitHub App (recommended)**, each sandbox gets an hour-long token from the
+app, which T3 Code renews while the sandbox runs and revokes when you delete it.
+
+- The token covers **every repository the app is installed on**, not just the sandbox's own, so an
+ agent can clone, push, and open pull requests on another of your repositories in the same
+ thread. It is the app's installation that decides this, so the app must still be installed on the
+ sandbox's own repository, or the launch warns with a link to install it.
+- Choose those repositories on GitHub: **Settings → Applications → Installed GitHub Apps →
+ Configure** next to the app (for an organization, the organization's **Settings → GitHub
+ Apps**), under **Repository access**. **Install on repositories** in the app's menu under
+ **Settings → Connections → Sandboxes** opens the same page. A running sandbox picks up a
+ change with its next token, at most about 40 minutes later; a resumed sandbox gets a new token
+ as it starts. Because every sandbox reaches every repository on that list, keep it to the
+ repositories you want agents to push to.
+- The app asks to write contents, pull requests and workflows, and to read checks, statuses and
+ actions. Without Workflows, GitHub refuses a push that changes `.github/workflows/`. An app
+ created before T3 Code asked for it lacks it: open the app's settings on GitHub
+ (**Settings → Developer settings → GitHub Apps → Edit**), set **Permissions → Repository
+ permissions → Workflows** to **Read and write**, and save. GitHub then asks each installation to
+ approve the change; until you accept it under **Installed GitHub Apps → Configure**, tokens keep
+ the old permissions.
+
### Let the agent use Boat
Off by default, and offered only for Boat. With it on, the agent in each sandbox can run `boat`
diff --git a/packages/contracts/src/sandbox.ts b/packages/contracts/src/sandbox.ts
index 6d818320aac92..14b15f3d170aa 100644
--- a/packages/contracts/src/sandbox.ts
+++ b/packages/contracts/src/sandbox.ts
@@ -1255,6 +1255,8 @@ const SANDBOX_GITHUB_APP_PERMISSIONS = {
checks: "read",
statuses: "read",
actions: "read",
+ // A push that changes `.github/workflows/` needs it, or GitHub refuses the push.
+ workflows: "write",
} as const;
/** The sandboxes' GitHub App's homepage on github.com. */
@@ -1280,7 +1282,8 @@ export const sandboxGithubAppManifest = (input: {
name: "T3 Code sandboxes",
url: input.homepageUrl,
redirect_url: input.redirectUrl,
- description: "Gives each T3 Code sandbox an hour-long token for one repository.",
+ description:
+ "Gives each T3 Code sandbox an hour-long token for every repository this app is installed on.",
public: false,
default_permissions: SANDBOX_GITHUB_APP_PERMISSIONS,
});