Repository navigation
Enforce the agent sandbox on the server - #14
Merged
Merged
Conversation
The sandbox was a variable in one MCP session: the REST API didn't know about it, ending it lifted every restriction, and webhooks, settings, imports and approvals ignored it. It is now a property of the API key or OAuth connection. - Access: each key and connection is Sandbox (only forks it created) or Full (its owner's role). New OAuth connections and new keys made in the admin UI start as Sandbox; existing keys keep Full. - A default-deny table lists the write routes a sandboxed caller may use. Everything else is refused in the REST layer, whichever tool or client sends it, and a test fails on any route not decided in it. - Writes must target a fork the same key or connection created. Uploads are limited to new images, PDFs, fonts and text; nothing executable, and nothing replaced. - start_agent_sandbox records the fork on the credential (REST: GET/POST /api/v1/sandbox, POST /api/v1/sandbox/end), so it applies to every session and survives a restart. Ending it on a Sandbox credential only hands the fork off. A sandboxed caller can discard its own forks. - Connected Apps (/cm/connected-apps) lists, changes and disconnects OAuth connections; API keys get the same Access setting. Letting a credential merge its own forks is stored here, settable only by a signed-in admin for an account that can merge, and enforced next. - MCP tools no longer block anything themselves; the server does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A database error while reading a sandbox no longer closes it: only a fork that is gone, merged or archived does. Other errors answer 503. - Starting a sandbox is an atomic claim; of two racing starts one wins and the other's fork is removed. - The no-replace check for sandboxed uploads also finds assets recorded with the old /assets prefix and files that exist only on disk. - A sandboxed caller comments only on pages in its own forks: comments notify people and go out through webhooks. - A Full key or connection refused because it has a sandbox open is told so, and how to end it. - MCP writes stop when the sandbox can't be read instead of going to the live page; a server without sandboxes (before 7.5) still works. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
Independent review (a different model) found no way out of the sandbox. Its findings are fixed in 19e84ac:
Left as is, on purpose:
Areas it found sound: gate coverage and route matching, ownership checks on every allowed route, upload type handling, settings escalation (only signed-in admins, via CSRF-protected forms), the sandbox lifecycle, and the admin pages. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #13. Second of three changes; review and merge #13 first.
Why
The agent sandbox was a variable inside one MCP session. The REST API didn't know about it, ending the sandbox lifted every restriction, and several tool groups (webhooks, site configuration, theme, redirects, imports, approvals, templates) never checked it. The only server-side control, sandbox-only API keys, still let bulk create, imports, revert and restore reach the live site, could write into anyone's fork, and couldn't be created from the admin UI. OAuth connections were never sandboxed.
What changes
Access is a property of the credential
sandbox_onlyflag is unchanged./cm/api-keys, and on a new Connected Apps page (/cm/connected-apps) where people can see, change and disconnect their OAuth connections; admins see everyone's.Enforced in the REST layer
sandboxWriteRoutes) lists the write routes a sandboxed caller may use, each with the reason it can't reach the live site. Everything else gets a 403 before its handler runs, whichever client or tool sent it.TestSandboxRoutes_EveryWriteRouteIsDecidedfails on any route not listed as allowed or refused.Sandbox state on the server
GET /api/v1/sandbox,POST /api/v1/sandboxandPOST /api/v1/sandbox/endrecord the open sandbox fork on the key or connection. It applies to every MCP session, survives restarts, and closes when a person merges, archives or deletes the fork.sandboxBlockis gone). The server decides, and its reason reaches the agent.Tests
/mcp: a Sandbox connection can't touch a live page, works through copy-on-write in a sandbox shared across sessions, can't publish, and is still restricted after submitting.go test -p 1 ./...passes.🤖 Generated with Claude Code