Skip to main content

Tools & MCP

MCP Gateway

Turn on MCP servers when you create a sandbox, then connect any MCP client to all of them through one gateway. Choose from 200+ servers in the Docker MCP Catalog, or bring your own.

Maintained by
E2B
How it works
Gateway runs inside the sandbox
Package
e2b
Language
TypeScript, Python

Set it up

Get started

Paste the prompt into your coding agent, or follow the steps yourself.

Paste this into your coding agent

Add the E2B MCP Gateway to this project.

  1. 1.Install e2b and an MCP client SDK (@modelcontextprotocol/sdk for TypeScript, mcp for Python) using the project's package manager.
  2. 2.The SDK needs the E2B_API_KEY environment variable. If it isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode it. Ask me for each MCP server's keys the same way.
  3. 3.Follow the MCP Gateway guide at https://docs.e2b.dev/mcp-gateway: create a sandbox with the MCP servers I need in its mcp config, then connect a client to sandbox.getMcpUrl() with the token from getMcpToken() as a Bearer header.
  4. 4.List the tools once and show me what came back from the gateway, then kill the sandbox.

Or set it up yourself

  1. 1. Install the SDKs

    npm install e2b @modelcontextprotocol/sdk
  2. 2. Set your API keys

    export E2B_API_KEY="e2b_..."
    export EXA_API_KEY="..."
  3. 3. Turn on MCP servers in a sandbox

    import Sandbox from 'e2b'
    
    const sandbox = await Sandbox.create({
        mcp: {
            exa: {
                apiKey: process.env.EXA_API_KEY!,
            },
        },
    });
  4. 4. Connect a client to the gateway

    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.getMcpUrl()),
        {
            requestInit: {
                headers: {
                    'Authorization': `Bearer ${await sandbox.getMcpToken()}`
                }
            }
        }
    );
    
    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();

Security

What runs in the sandbox

The MCP servers run inside the sandbox, on an internet-connected Linux machine, not on your host.

  • ServersThe MCP servers you list in the mcp config, from the Docker MCP Catalog or a custom GitHub repo.
  • AccessClients connect through the gateway URL with a per-sandbox Bearer token. Inside the sandbox it is at localhost:50005/mcp.
  • SecretsEach server's keys go in the mcp config when you create the sandbox, so the server can use them there.
  • LifetimeThe gateway lives with its sandbox. Call kill() when your agent is done with the tools.

3B+ sandboxes started

Give every agent a machine