Skip to content

feat: let agents on a sandbox ask the host for a sub-sandbox - #20

Merged
OmarAlex24 merged 4 commits into
feat/sandbox-agent-skillfrom
feat/sandbox-sub-sandbox-requests
Nov 11, 2026
Merged

OmarAlex24 merged 4 commits into
feat/sandbox-agent-skillfrom
feat/sandbox-sub-sandbox-requests

Conversation

@OmarAlex24

@OmarAlex24 OmarAlex24 commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Problem

#16 lets an agent on the host give a subagent its own sandbox. Most chats, though, run on a sandbox, and sandboxes run the official T3 release. Its MCP has no target.sandbox, and the configs, provider keys and sub-sandbox logic live on the host. So an agent inside a sandbox had no way to ask for a sub-sandbox.

Solution

The host installs a small MCP helper on each chat's sandbox. The helper turns an agent's request into a file. The host picks up those files and runs #16's path on behalf of the chat. It works only while the host (the Mac) is awake.

Inside the sandbox (subSandboxHelper.ts):

  • The helper. ~/.t3/userdata/sub-sandbox/mcp.mjs uses Node built-ins only. The fork's own MCP registration already needs node; without it, the install warns and skips. It has two tools:
    • sandbox_delegate(task, size?, requestId?): queues a task to run on a new sub-sandbox.
    • sandbox_task_status(id, waitSeconds ≤ 30): reports the status, and the result at the end.
  • Registration. The helper is registered in Claude's ~/.claude.json, the same way the fork registers its other MCP servers. It is also listed in ~/.t3/mcp-servers.json, so the template scrub removes it.
  • Requests.
    • A request is a file in requests/, written via a temp file and a rename. It carries the thread id, working directory, pushed branch and the thread's model (from t3 thread show --json).
    • Official T3 0.1.8 passes T3CODE_THREAD_ID to Claude, and the MCP servers Claude spawns inherit it.
    • The host claims a request by moving it to claimed/, and the helper withdraws one by moving it to withdrawn/. Only one rename can win, so a withdrawn request never starts.
    • The same requestId never creates a second request.
  • Unanswered requests. If the host hasn't picked a request up after 45 s, the helper withdraws it and tells the agent the Mac may be asleep or offline, so it should run the work locally. The wait is 20 s when the host hasn't polled for over 3 minutes.

On the host (SubSandboxRequests.ts):

  • Polling. The host polls through driver.execute (new SandboxProvisioner.runScript). The bridge's bearer only has orchestration:* scopes and can't read or write files.
    • Every 15 s while the chat has a turn running on the host, an open request, or a request in the last 5 minutes. Whether a turn is running is a local database read, so it costs nothing.
    • Every 60 s otherwise. Stopped sandboxes are never polled.
    • A poll with nothing pending is one short exec that prints a few bytes. Each request adds about 4 execs for its status writes.
  • Handling.
    • Each request runs feat: let delegate_task start its child on a new sandbox, within limits #16's path for the chat's host thread (SandboxRecord.threadId): config, caps, sizes, createSubSandbox, peer link, RemoteDelegation, and checkWork at the end.
    • The clone comes from the record's repository, at the request's branch.
    • Status goes back to responses/ as queued, then starting_sandbox, then running (with the task id and sub-sandbox), then completed, failed or cancelled (with the result and where any kept work lives).
  • Refusals. Each refusal reaches responses/ with its reason: concurrency_full, Linked environments off, no config, size too big, or no turn running on the host.
  • Validation. Before any id from the sandbox reaches a path or a shell, it must match ^[A-Za-z0-9_-]{1,64}$. Branches are checked against a strict pattern. The parent thread comes from the host's record, never from the request.
  • Restarts.
    • Nothing starts until the queued write lands on the sandbox.
    • After a restart, a request that already has a task is followed to its end.
    • A request caught mid-start is marked failed and never runs twice.
  • Install. The helper installs at launch, after the t3-sandbox-files skill, and on every resume of a chat's sandbox. A sub-sandbox never gets it. A failure is only a warning. The template scrub removes the helper's folder, pending requests included.
  • Limits at 0. With the config's limits at 0, the helper still installs, and requests are refused with a clear message. Raising the limit then works without re-provisioning.
  • Docs. docs/user/remote-access.md "Sandboxes for subagents" and docs/internals/sandbox-environments.md explain the flow and the awake-Mac requirement.

Known limitations

  • Needs the Mac awake. The configs, keys and sub-sandbox logic live there.
  • Needs a turn on the host. RemoteDelegation records the task on the chat's active turn on the host, so a turn that didn't go through T3 Code on the Mac or phone is refused. When the chat is idle, the 60 s poll can mean the agent hears "host didn't answer" instead of that refusal.
  • Claude only. Codex and Pi threads on a sandbox don't get the tools.
  • Late results. A result that arrives after the asking turn ended starts a new turn on the chat, which the bridge should pass to the sandbox. This hasn't been checked live.
  • Model. The child runs on the model from t3 thread show, without its options, or on the bridge's Claude fallback.
  • Short waits. The pickup wait is 45 s and status waits are capped at 30 s, so tool calls stay under the 60 s timeout some MCP clients use.
  • Longer resume wait. A new 30 s resume step makes the bridge's resume wait 16 minutes instead of 15½.
  • Crash leak. A server crash right after a sub-sandbox is created can leave it running, as in feat: let delegate_task start its child on a new sandbox, within limits #16. The failure message tells the user to delete it.
  • Task card. The task card lives on the host thread. While the sandbox's own thread is on screen, the user only sees the tool result.
  • Not run live. Nothing has run against a real Boat sandbox yet; everything is tested with fakes.

Test plan

  • subSandboxHelper.test.ts, with the helper run under Node against a temporary folder:
    • writing requests, and idempotency per requestId;
    • withdrawal and the host-unresponsive message;
    • status waits;
    • parsing the poll output, including invalid ids.
  • SubSandboxRequests.test.ts:
    • each request is picked up and handled once;
    • after a restart, a request with a task is followed and one caught mid-start never runs twice;
    • the happy path through SubSandboxes with a sandbox chat as parent;
    • refusals reaching responses/;
    • poll pacing.
  • SandboxProvisioner.test.ts: the helper installs at launch, is backfilled on resume, is skipped on sub-sandboxes, and is removed by the template scrub
  • agentContextBudget.json unchanged: the T3 MCP tool list isn't touched
  • All sandbox browser test files plus ChatView.browser and Sidebar.browser in apps/web (22 files, vp test run --project browser) on this branch: 112 of 112 pass
  • vp run check:changed origin/feat/sandbox-environments on this branch: format, lint, knip, graphql, typecheck (38 packages) and React compiler pass. 843 of 844 tests pass; the one failure, sandboxSetup.test.ts > tailscaleScript > falls back to userspace, joins with the key as a 0600 file, and the scrub logs out, fails on feat/sandbox-environments too.

🤖 Generated with Claude Code

OmarAlex24 and others added 4 commits November 11, 2026 15:25
…andbox

A parent on a sandbox has no checkout on this machine, so start can take
the repository and pushed branch its clone tracks instead of reading the
host's checkout, and copies env files only from a real checkout. A
caller name picks the words of a refusal, so an agent asking from a
sandbox is not told about target.sandbox.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sandboxes run the official T3 Code, so agents there get sandbox_delegate
and sandbox_task_status from a small MCP server T3 Code installs: Node
built-ins only, registered in Claude's MCP list like the servers a config
copies. Requests and responses are files under ~/.t3/userdata/sub-sandbox,
written by rename, and a request the host does not pick up within 45 s is
withdrawn with a message to do the work locally.

The launch installs it after T3 Code's skill, every resume of a chat's
sandbox rewrites it before T3 starts, and a subagent's own sandbox never
gets it. A failure is only a warning. The template scrub removes its
folder with any pending requests. The provisioner can now run T3 Code's
own scripts on a running sandbox for the host's poll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The host polls each running chat sandbox for helper requests with one
provider exec: every 15 s while the chat runs a turn here or has a
request open, every 60 s otherwise, and once per running stretch where
the helper is missing. Each request starts through SubSandboxes and
RemoteDelegation on behalf of the chat's thread here, so the same
config, limits, sizes and end-of-task checkWork apply, and every status,
refusal and result is written back. Nothing starts before the first
answer lands, and a restart recovers open requests from their responses
without starting any twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@OmarAlex24
OmarAlex24 added this pull request to stack #13 November 11, 2026 15:40
@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Nov 11, 2026
@OmarAlex24 OmarAlex24 changed the title feat/sandbox sub sandbox requests feat: let agents on a sandbox ask the host for a sub-sandbox Nov 11, 2026
@OmarAlex24
OmarAlex24 merged this pull request into feat/sandbox-environments Nov 11, 2026
8 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant