SandboxMCP clients

Use a sandbox from MCP clients

There are two ways to reach a sandbox over the Model Context Protocol:

PathToolsRuns
Local stdio serverRun code, run commands, read, write, list and search files.On your machine: tangle mcp serve or createMcpServer(box).
Hosted computer-use endpointComputer use: control the sandbox’s desktop.In the sandbox, over HTTPS with a scoped token.

Serve sandbox tools from your machine

tangle mcp serve starts an MCP server on stdio for one sandbox. Your MCP client starts it as a command.

npm install -g @tangle-network/sandbox-cli @modelcontextprotocol/sdk
tangle sandbox create --name mcp-box

The CLI loads @modelcontextprotocol/sdk when the server starts, so install it where the CLI can import it.

Add the server to your client. Claude Desktop and Cursor use the same shape:

{
  "mcpServers": {
    "tangle-sandbox": {
      "command": "tangle",
      "args": ["mcp", "serve", "mcp-box"],
      "env": { "TANGLE_API_KEY": "sk-tan-..." }
    }
  }
}
ClientConfig file
Claude Desktopclaude_desktop_config.json, under Settings, Developer
Cursor.cursor/mcp.json in the project, or ~/.cursor/mcp.json
Zed and othersThe client’s MCP server settings, with the same command, args and env
FlagDefaultEffect
--session <id>mcp-localThe kernel session. Variables in sandbox_run_code persist for that session.
--name <name>tangle-sandboxThe server name the client shows.

The server stops when the client closes its stdin. The sandbox keeps running; delete it with tangle sandbox delete mcp-box --force when you are done.

The tools are sandbox_run_code, sandbox_exec, sandbox_read, sandbox_write, sandbox_list and sandbox_search, the same set as the framework tool packs. A failed call returns an MCP result with isError: true and the message.

Build the server in your own program

createMcpServer(box, options) returns { server, connect, close }. Use it when your program picks the sandbox or the tools:

import { Sandbox } from "@tangle-network/sandbox";
import { createMcpServer } from "@tangle-network/sandbox/agent";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
 
const client = new Sandbox({
  apiKey: process.env.TANGLE_API_KEY!,
  baseUrl: "https://sandbox.tangle.tools",
});
 
const box = await client.get(process.env.SANDBOX_ID!);
if (!box) throw new Error(`Sandbox ${process.env.SANDBOX_ID} not found`);
 
const { connect } = await createMcpServer(box, {
  sessionId: "claude-desktop",
  allow: ["sandbox_run_code", "sandbox_read"],
});
await connect(new StdioServerTransport());

Point the client’s command at node and this file, with TANGLE_API_KEY and SANDBOX_ID in env. Without sessionId, every caller shares one default kernel, so give each client its own session.

Control the sandbox desktop over MCP

A sandbox created with the desktop capability serves computer use as MCP tools over HTTPS. Create it with capabilities: ["computer_use"], or turn on Enable remote desktop when you create a sandbox in the dashboard. The desktop needs an image that includes it.

This program checks the endpoint’s URL, token scope, expiry and client configuration. It deletes the sandbox when the check finishes.

import assert from "node:assert/strict";
import { Sandbox } from "@tangle-network/sandbox";
 
const client = new Sandbox({
  apiKey: process.env.TANGLE_API_KEY!,
  baseUrl: "https://sandbox.tangle.tools",
});
 
const box = await client.create({ agent: false, capabilities: ["computer_use"], resources: { memoryMB: 4096 }, maxLifetimeSeconds: 300 });
try {
  const endpoint = await box.getMcpEndpoint({ capabilities: ["computer_use"], ttlMinutes: 5 });
  assert(endpoint.url.startsWith("https://"));
  assert(endpoint.authToken.length > 0);
  assert(endpoint.capabilities.includes("computer_use"));
  assert(Date.parse(endpoint.expiresAt) > Date.now());
  const server = endpoint.config.mcpServers[endpoint.serverName];
  assert(server, "The MCP configuration did not include its server entry");
  assert.equal(server.url, endpoint.url);
  assert.equal(server.headers.Authorization, `Bearer ${endpoint.authToken}`);
  console.log("Validated hosted MCP endpoint configuration");
} finally {
  await box.delete();
}

endpoint.config is a standard mcpServers block with an HTTP entry: the sandbox’s /mcp URL and an Authorization header. To use it with an MCP client that speaks the HTTP transport, pass endpoint.config to the client and keep the sandbox running for that client’s session.

FieldMeaning
urlThe sandbox’s MCP endpoint.
authTokenA short-lived token limited to the requested capabilities.
expiresAtWhen the token expires. Call getMcpEndpoint() again for a new one.
serverNameThe entry name in config, tangle-sandbox unless you pass serverName.
capabilitiesWhat the token may do: ["computer_use"].

The token works only on the MCP endpoint. The sandbox’s command and file routes refuse it, so handing it to a client grants computer use and nothing else. The desktop shares the sandbox’s memory, so size resources.memoryMB for the desktop plus your workload. Delete the sandbox when you are done.

The REST call is GET /v1/sandboxes/{id}/mcp?capabilities=computer_use. Python has no getMcpEndpoint; call that route with client.fetch("GET", f"/v1/sandboxes/{box.id}/mcp?capabilities=computer_use").

Give coding agents in the sandbox MCP servers

To give Claude Code, Codex or OpenCode inside the sandbox extra MCP servers, list them in the agent’s AgentProfile. To give them accounts such as GitHub or Gmail, use connections.

For retries and duplicate tool calls from an MCP client, see Retries and duplicate work.

Next