Skip to main content
You can prepull MCP server Docker images during template build time to significantly improve runtime performance.

How it works

When you build a template with prepulled MCP servers, the Docker images for those servers are downloaded and cached during the build process. This means when you create a sandbox from that template, the MCP servers are ready to use immediately without waiting for image downloads.
You must use the MCP gateway enabled template (mcp-gateway) as your base template to use this feature.

Building a template with MCP servers

Use the betaAddMcpServer() method (TypeScript) or beta_add_mcp_server() method (Python) to prepull MCP server images during template build. You can pass a single server or an array of servers. The server names (like "browserbase" and "exa") correspond to the keys defined in the Available Servers documentation.
import "dotenv/config";
import { Template } from "e2b";

export const template = Template()
  .fromTemplate("mcp-gateway")
  .betaAddMcpServer(["browserbase", "exa"]);

await Template.build(template, {
  alias: "my-mcp-gateway",
  cpuCount: 8,
  memoryMB: 8192,
  onBuildLogs: console.log,
});

Using the template

Once built, create sandboxes from your template alias. You still need to provide the configuration for each MCP server.
import { Sandbox } from "e2b";

const sandbox = await Sandbox.betaCreate({
    template: "my-mcp-gateway",
    mcp: {
        browserbase: {
            apiKey: process.env.BROWSERBASE_API_KEY!,
            geminiApiKey: process.env.GEMINI_API_KEY!,
            projectId: process.env.BROWSERBASE_PROJECT_ID!,
        },
        exa: {
            apiKey: process.env.EXA_API_KEY!,
        },
    },
});

Learn more

For more information about working with templates, see:
I