Skip to main content
You can connect to the MCPs running inside the sandbox both from outside and inside the sandbox.

From outside the sandbox

To connect to the MCPs running inside the sandbox, use the sandbox.betaGetMcpUrl() in JavaScript and sandbox.beta_get_mcp_url() in Python.
import Sandbox from 'e2b'
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';

const sandbox = await Sandbox.betaCreate({
    mcp: {
        exa: {
            apiKey: process.env.EXA_API_KEY!,
        },
        notion: {
            internalIntegrationToken: process.env.NOTION_API_KEY!,
        },
    },
});

const client = new Client({
    name: 'e2b-mcp-client',
    version: '1.0.0'
});

const transport = new StreamableHTTPClientTransport(
    new URL(sandbox.betaGetMcpUrl()), 
    {
        requestInit: {
            headers: {
                'Authorization': `Bearer ${await sandbox.betaGetMcpToken()}`
            }
        }
    }
);

await client.connect(transport);

const tools = await client.listTools();
console.log('Available tools:', tools.tools.map(t => t.name));

await client.close();
await sandbox.kill();

From inside the sandbox

If you need to access the MCP gateway from within the sandbox itself, it’s available at:
http://localhost:50005/mcp
You’ll need to include the Authorization header with the MCP token when making requests from inside the sandbox. How that is added depends on the MCP client you use:

Claude

claude mcp add --transport http e2b-mcp-gateway <url goes here> --header "Authorization: Bearer <token goes here>"

OpenAI Agents

import { MCPServerStreamableHttp } from '@openai/agents';

const mcp = new MCPServerStreamableHttp({
    url: mcpUrl,
    name: 'E2B MCP Gateway',
    requestInit: {
        headers: {
            'Authorization': `Bearer ${await sandbox.betaGetMcpToken()}`
        }
    },
});

Official MCP Client

import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';

const client = new Client({
    name: 'e2b-mcp-client',
    version: '1.0.0'
});

const transport = new StreamableHTTPClientTransport(
    new URL(sandbox.betaGetMcpUrl()), 
    {
        requestInit: {
            headers: {
                'Authorization': `Bearer ${await sandbox.betaGetMcpToken()}`
            }
        }
    }
);
await client.connect(transport);
This list is not exhaustive. You can find more examples in the E2B Cookbook.

Debugging with MCP Inspector

The MCP Inspector is a useful tool for debugging and testing your MCP server setup. Get the command to run:
npx @modelcontextprotocol/inspector --transport http --url <your-mcp-url> --header "Authorization: Bearer ${mcpToken}"
Run the command in your terminal. This will open a web interface where you can:
  • Browse available tools
  • Test tool calls with different parameters
  • Inspect request/response payloads
  • Debug connection issues
I