Skip to content

MCP

An MCP server gives a coding agent tools: a database to query, an issue tracker to read, an API to call. fastsandbox reaches MCP servers in two distinct ways, which differ in where the server runs, who registers it, and what it can touch.

Servers of the agent's kit Servers of the MCP gateway
Registered by The task or the spec, mcp=[...] or with_mcp(...), written into the configuration of the agent when the sandbox is created sbx mcp add, once, for every sandbox of the user; a sandbox loads those it uses
Agents claude, copilot and opencode only The agents whose kit registers the gateway: claude, copilot and opencode were measured
Where the server runs On the host (McpServer.host), elsewhere on the network (McpServer.remote), or in the sandbox (McpServer.stdio) Behind the gateway, on the host side of the sandbox
Credentials A token drawn for each run, in clear in the sandbox, for a server of the host; a bearer you give, for a remote one Held on the host by sbx: the sandbox never holds them
Guide Connect MCP tools Connect MCP tools, MCP gateway

Servers of the agent's kit

A McpServer is one of three kinds:

  • McpServer.host(name, port): a server your program runs on the loopback of the host, which the agent reaches at http://host.docker.internal:<port>/mcp. The launch draws a token for each run; the server checks it to tell that sandbox from any other local process. The sandbox holds the token in clear, in DOCKER_SANDBOX_MCP_<NAME>_TOKEN, where any process in it can read it.
  • McpServer.remote(name, url): a server elsewhere, which the agent calls itself; the hosts of its URL are allowed for the sandbox. A bearer given with with_bearer_env is read from a variable of the sandbox: make it a proxied key for the host of the server to keep its value out.
  • McpServer.stdio(name, program): a program started in the sandbox, as the agent's user, with the whole environment of the sandbox.

Other agents raise InvalidKitError: their kits have no way yet to register a server.

Servers of the MCP gateway

The MCP gateway of Docker Sandboxes serves the servers registered on the host with sbx mcp add, one endpoint per sandbox, http://mcp-gateway.docker.internal/mcp from inside it. fastsandbox does not register servers: it checks a registration, reads the mode of the gateway, and loads or unloads a registered server for one sandbox. In the dynamic mode, an agent can load any server registered on the host by itself; a static set of servers, given at creation, prevents it. See Static and dynamic gateways.

The trust boundary

An MCP server acts outside the sandbox, whatever contains the agent:

  • A server of the host runs with the rights of your user, on your machine. A server the gateway starts from a local program also runs on the host, outside the isolation of any sandbox: treat it as a trusted integration of the host.
  • A remote server acts with the rights of the credentials it holds: what the agent asks it to do, it does.
  • A stdio server in the sandbox is contained like the agent, and sees what the agent sees.

Give an agent only the servers, and the tools, its work needs.

Next