Skip to content

Enforce the agent sandbox on the server - #14

Merged
jonradoff merged 2 commits into
mainfrom
security/server-sandbox
Nov 10, 2026
Merged

jonradoff merged 2 commits into
mainfrom
security/server-sandbox

Conversation

@jonradoff

Copy link
Copy Markdown
Collaborator

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

  • Every API key and OAuth connection has an Access setting. Sandbox means it can read the site but change only forks it created. Full means it can do anything its owner's role allows.
  • New OAuth connections default to Sandbox on the consent page, as do new keys created in the admin UI. Existing keys keep Full, and the REST sandbox_only flag is unchanged.
  • The settings live on the consent page, on /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.
  • The setting that lets a credential merge its own forks is stored here. Only a signed-in admin can turn it on, and only for an account whose role can merge. The next PR enforces it.

Enforced in the REST layer

  • A default-deny table (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_EveryWriteRouteIsDecided fails on any route not listed as allowed or refused.
  • Writes must target a fork created by the same key or connection. Forks now record the credential that created them.
  • Sandboxed uploads are limited to new images, PDFs, fonts and plain text. HTML, JS, CSS, SVG, XML and JSON are refused, and so is replacing an existing file.

Sandbox state on the server

  • GET /api/v1/sandbox, POST /api/v1/sandbox and POST /api/v1/sandbox/end record 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.
  • On a Sandbox credential, ending the sandbox only hands the fork off; the restriction stays. On a Full credential the sandbox is an opt-in safety net.
  • A sandboxed credential can now discard forks it created, and no one else's.
  • The MCP tools no longer block anything themselves (sandboxBlock is gone). The server decides, and its reason reaches the agent.

Tests

  • A router walk checks every write route is decided, and sends every refused route as both a sandboxed key and a Full key with an open sandbox. All get 403 and the database is unchanged.
  • Own-fork rules are tested with real keys, as are uploads and the opt-in sandbox on a Full key.
  • The sandbox closes when its fork is merged, archived or deleted.
  • Admin pages: people change only their own connections, and only an admin can allow self-merge.
  • The consent page defaults to Sandbox.
  • End to end through /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

jonradoff and others added 2 commits November 9, 2026 21:34
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>
@jonradoff

Copy link
Copy Markdown
Collaborator Author

Independent review (a different model) found no way out of the sandbox. Its findings are fixed in 19e84ac:

  • A database error while reading a sandbox could close it and let the next write go live. Only a fork that is gone, merged or archived closes it now; other errors answer 503.
  • Two racing starts could both open a sandbox. Starting one is now an atomic claim.
  • The no-replace upload check missed assets recorded with the old /assets prefix and files that exist only on disk. It checks both now.
  • Comments from a sandboxed caller fired webhooks and mentions from live pages. Sandboxed callers can now comment only on pages in their own forks.
  • A Full key refused because it has a sandbox open is now told so, and how to end it.
  • MCP writes stop when the sandbox can't be read, instead of going to the live page.

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.

@jonradoff
jonradoff changed the base branch from security/oauth-identity to main November 10, 2026 11:03
@jonradoff
jonradoff merged commit 55483fa into main Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant