Architecture · Decision record 0011
ADR 0011: Ship-a-PR with a hand-written Engineer loop, Vercel Sandbox and a GitHub App
On this page
- Status: Accepted
- Date: 2026-11-25
- Amends: SPEC "Ship-a-PR: an Engineer sub-agent on the Claude Agent SDK inside a sandbox" and the matching exception in SPEC §Architecture and ADR 0001
Context#
Ship-a-PR (M5) takes one improvement from a Repo X-ray, implements it in an isolated copy of the repository, runs the repo's own tests and lint, and opens a pull request on a repository the owner has authorised, after a human approves the diff. Any other repository gets a downloadable patch and test report instead.
The spec planned the Engineer sub-agent on the Claude Agent SDK. Three constraints rule that out:
- $0, keyless (ADR 0003). The Agent SDK drives Claude models only, which need a paid key. Delegate's default chains are free open models behind our router; an Engineer that only works with a paid key would make the hero flow unusable on the default deployment.
- Controls live in our loop (ADR 0001). Capability checks, the policy engine, budgets and typed
RunEvents sit around every tool call inrunAgentLoop. The Agent SDK runs its own loop and its own tools (shell, file edits), which is exactly where those controls must be. - Serverless budget. Production is Vercel Hobby: 300 s per function, resumed from the event log (ADR 0007). An external agent process holds state we cannot checkpoint into
run_events.
Decision#
- The Engineer is our own loop. It is
runAgentLoopwith five sandbox tools (read_file,list_dir,search,write_file,run), theworkerrole from the router, and an outer verify loop: after the model stops, the runtime runs the detected test command itself; failing output goes back to the model for another round. Rounds, iterations per round, tokens (the run budget) and wall time are all capped. The prompt ispackages/.runtime/ prompts/ ship-a-pr.engineer.v1.md - Sandbox interface, two implementations.
Sandboxexposes exec with argv (never a shell string), file read/write and a two-phase network policy.VercelSandbox(@vercel/, free on Hobby: 5 CPU-hours a month, 45 minute sessions, over-quota pauses rather than bills; OIDC auth on Vercel) is the production implementation: network open to GitHub and package registries only while cloning and installing, then restricted to package registries.sandbox LocalProcessSandbox(temporary directory,child_processwith a scrubbed environment and hard timeouts) is for development and tests; it is not an isolation boundary and refuses to start whenNODE_ENV=production.DELEGATE_SANDBOX=vercel|localselects one; the default islocalin development andvercelin production. If Vercel Sandbox is unavailable, the run fails with a clear error; untrusted code never runs in the web function. - The Engineer is an unprivileged agent. A coding agent must read the repository, which is untrusted content, so the quarantined-reader rule (ADR 0002) cannot apply to it. Instead the Engineer holds no privilege worth stealing: its only capabilities are
sandbox.read,sandbox.writeandsandbox.exec, which reach nothing outside the sandbox; it sees no secrets; and nothing it produces leaves the sandbox until a human has approved the exact diff. - Confinement in code. Every path is checked lexically (no absolute paths, no
.., no.git, no.github/) and then resolved inside the sandbox (workflows realpath) so a symlink cannot point a write outside the repository.runaccepts only the commands detected frompackage.jsonscripts,pyproject.tomlor theMakefileplus a read-only pair (git status --short,git diff --stat), each with a per-command timeout, as argv without a shell. Changes made by installing dependencies are snapshotted before the Engineer starts and excluded from the diff. The final diff is checked again before it is shown for approval: no workflow files, no symlinks, no submodules, size-capped. - No credentials in the sandbox. The sandbox gets no environment secrets and no git credentials. The server reads the changed files out of the sandbox and creates the commit itself through the GitHub git data API (blobs, tree, commit, ref) and then the pull request.
- GitHub App authorisation. The owner creates a GitHub App (Contents and Pull requests read & write, Metadata read, no webhook) and installs it only on chosen repositories. The server signs an RS256 JWT with
node:crypto, looks up the installation for the target repository, and mints an installation token scoped to that one repository with onlycontents: writeandpull_requests: write. Tokens are never logged, persisted or emitted; they live for one request sequence. - Approval is a gate in code.
github.open_prhas capabilityrepo.write, a side-effect capability the policy baseline always routes torequire_approval. The mission emitsship.approval.requestedwith the diff and the before/after test results and waits for a human decision; a timeout is a rejection. Which installation may be used is decided outside the mission: it takes an injectedfindInstallation(owner, repo). The web app scopes that lookup to the visitor's own workspace (installations they connected through "Connect GitHub"), so a visitor gets real pull requests on repositories their own installation covers and a patch everywhere else, even if they paste someone else's repository URL. Owner mode is the second source: the owner's own App installation is looked up directly. Without either, the guest policy (ship-demo) deniesgithub.open_proutright; a connected visitor runs undership-connected(approval required, zero spend), the owner undership-owner. The installation token is always minted for the one input repository, so an installation that does not cover it fails closed to a patch. - Durable steps. The mission is a fixed plan (
prepare → baseline → implement → verify → ship) onrunPlannedMission. Each step's state is an artifact in the log (workspace, test reports, diff), so a run cut at 300 s resumes: the sandbox is reattached by id or rebuilt from the recorded base commit plus the recorded patch.
Consequences#
- The Engineer is weaker than a frontier coding agent on free models. It suits small, test-backed improvements (
effort: S|M), which is what Repo X-ray proposes. - We own the coding loop's tools and their security tests; the red-team suite gains sandbox-escape, exfiltration and approval-bypass cases for them.
- Owner mode is a development-only flag (
DELEGATE_OWNER_MODE, ignored in production), so real pull requests are opened from the owner's own environment; the production deployment produces patches. Changing that needs real owner authentication (M7 RBAC), not a flag. - Vercel Sandbox is the one external service on this path. It is free on Hobby and needs no extra account beyond the Vercel project the app already deploys to; self-hosters without it can run
DELEGATE_SANDBOX=localonly on machines they trust.