This guide is for deployments where an agent runs inside an isolated container, subprocess, or remote worker and still needs MCP access. In that setup, the sandbox itself becomes part of your trust boundary. The core recommendation is simple: use FastMCP as the capability boundary. Run a remote FastMCP server, authenticate the sandbox with short-lived scoped credentials, and keep privileged credentials on the server side.Documentation Index
Fetch the complete documentation index at: https://gofastmcp.com/llms.txt
Use this file to discover all available pages before exploring further.
When to Use This Pattern
This pattern is useful when:- your agent runs in an ephemeral container or subprocess
- you do not want long-lived credentials inside that sandbox
- you need per-run, per-tenant, or per-job scoping
- the sandbox must call internal APIs, databases, or upstream MCP servers indirectly
What Changes in a Sandboxed Deployment
A desktop MCP client usually runs on a developer’s machine and launches local servers with configuration the developer controls. A sandboxed agent is different:- It often runs in an ephemeral container or subprocess.
- Its filesystem may be inspected after the fact.
- Its environment variables may be broader than you intend.
- You may launch many sandboxes concurrently for different users, tenants, or jobs.
Recommended Architecture
Use this shape by default: The sandbox gets:- the MCP server URL
- a short-lived token scoped to its job, tenant, or run
- no long-lived upstream credentials
- verifies the sandbox token
- authorizes the request from token claims, scopes, or other server-side policy
- exposes only the tools that sandbox should see
- talks to internal APIs, databases, or upstream MCP servers on the sandbox’s behalf
Prefer HTTP for Sandboxed Agents
For sandboxes, prefer a remote HTTP server over a local STDIO server. STDIO is still excellent for local development, but a remote HTTP server is usually the better production boundary for sandboxed agents because:- authentication is explicit
- the server lifecycle is independent from the sandbox lifecycle
- secrets stay on the server
- one deployment can safely serve many sandboxes
- auditing and revocation happen in one place
Use Short-Lived, Scoped Credentials
For sandboxed agents, it is usually cleaner to issue credentials for the sandbox session than to place long-lived upstream credentials directly inside the container. In practice, that usually means issuing a short-lived bearer token for each sandbox, run, or tenant and validating it on your FastMCP server with a token verifier.- sandbox or run id
- tenant or installation id
- user or actor id when applicable
- expiration
- optional capability scopes
Expose Capabilities, Not Raw Access
The sandbox should not need:- GitHub app private keys
- database passwords
- upstream OAuth client secrets
- cloud provider credentials
get_recent_updateswrite_summaryfetch_repo_contextpublish_review_comment
write_summary lets the server decide where and how to persist the summary. A tool like run_sql or call_internal_api pushes privilege and policy into the sandbox where they are much harder to control.
Sandboxed agents behave best when those tools are narrow and structured:
mutate_state(kind: str, payload: dict).
Narrow tools also let you express different policies per tool instead of creating one large privileged escape hatch.
Use a Proxy When Upstream Systems Are More Privileged
If the sandbox needs access to other MCP servers or internal systems, put FastMCP in front of them instead of forwarding secrets into the sandbox. This is where proxying becomes useful. Your public-facing FastMCP server can authenticate the sandbox, then forward allowed capabilities to upstream systems with stronger credentials. Typical examples:- a sandbox-safe MCP gateway in front of internal MCP servers
- a FastMCP layer in front of internal HTTP APIs
- a job-scoped server that fronts a Git provider, issue tracker, or storage system
mcp.json for Sandboxed Clients
If your sandboxed agent is configured throughmcp.json, keep that configuration minimal. Point it at the remote FastMCP server and pass only the values the sandbox actually needs.
mcp.json. That is usually the right tradeoff for sandboxes. Avoid baking long-lived credentials directly into generated config files, and avoid treating mcp.json as the place where secret material should live.
That is all this section needs to do: tell the sandbox where the server lives. Keep auth and secret handling elsewhere.
For configuration details, see MCP.json.
Common Mistakes
The same few mistakes show up again and again in sandboxed deployments:- passing long-lived API keys directly into the sandbox
- treating helper scripts in the sandbox as a security boundary
- exposing broad mutation tools instead of narrow capabilities
- using one shared token for every sandbox
- relying on STDIO inheritance for configuration in production
Production Checklist
Before shipping a sandbox-facing FastMCP server, check these:- The sandbox connects over HTTP, not with privileged local credentials.
- Tokens are short-lived and scoped to a run, tenant, or job.
- The FastMCP server verifies tokens on every request.
- Long-lived secrets stay on the server side.
- Tools are narrow, explicit, and structured.
- Upstream privileged systems sit behind the FastMCP server or proxy.
- Revocation and audit live at the server boundary, not inside the sandbox.

