Documentation Index Fetch the complete documentation index at: https://e2b.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Claude Code is Anthropic’s agentic coding tool. E2B provides a pre-built claude template with Claude Code already installed.
CLI
Create a sandbox with the E2B CLI .
Once inside the sandbox, start Claude Code.
Run headless
Use -p for non-interactive mode and --dangerously-skip-permissions to auto-approve all tool calls (safe inside E2B sandboxes).
JavaScript & TypeScript
Python
import { Sandbox } from 'e2b'
const sandbox = await Sandbox. create ( 'claude' , {
envs: { ANTHROPIC_API_KEY: process.env. ANTHROPIC_API_KEY },
})
const result = await sandbox.commands. run (
`claude --dangerously-skip-permissions -p "Create a hello world HTTP server in Go"`
)
console. log (result.stdout)
await sandbox. kill ()
Example: work on a cloned repository
JavaScript & TypeScript
Python
import { Sandbox } from 'e2b'
const sandbox = await Sandbox. create ( 'claude' , {
envs: { ANTHROPIC_API_KEY: process.env. ANTHROPIC_API_KEY },
timeoutMs: 600_000 ,
})
await sandbox.git. clone ( 'https://github.com/your-org/your-repo.git' , {
path: '/home/user/repo' ,
username: 'x-access-token' ,
password: process.env. GITHUB_TOKEN ,
depth: 1 ,
})
const result = await sandbox.commands. run (
`cd /home/user/repo && claude --dangerously-skip-permissions -p "Add error handling to all API endpoints"` ,
{ onStdout : ( data ) => process.stdout. write (data) }
)
const diff = await sandbox.commands. run ( 'cd /home/user/repo && git diff' )
console. log (diff.stdout)
await sandbox. kill ()
Structured output
Use --output-format json to get machine-readable responses — useful for building pipelines or extracting specific results.
JavaScript & TypeScript
Python
import { Sandbox } from 'e2b'
const sandbox = await Sandbox. create ( 'claude' , {
envs: { ANTHROPIC_API_KEY: process.env. ANTHROPIC_API_KEY },
})
const result = await sandbox.commands. run (
`claude --dangerously-skip-permissions --output-format json -p "Review this codebase and list all security issues as JSON"`
)
const response = JSON . parse (result.stdout)
console. log (response)
await sandbox. kill ()
Streaming output
Use --output-format stream-json to get a real-time JSONL event stream — including tool calls, token usage, and result metadata.
JavaScript & TypeScript
Python
import { Sandbox } from 'e2b'
const sandbox = await Sandbox. create ( 'claude' , {
envs: { ANTHROPIC_API_KEY: process.env. ANTHROPIC_API_KEY },
})
const result = await sandbox.commands. run (
`cd /home/user/repo && claude --dangerously-skip-permissions --output-format stream-json -p "Find and fix all TODO comments"` ,
{
onStdout : ( data ) => {
for ( const line of data. split ( ' \n ' ). filter (Boolean)) {
const event = JSON . parse (line)
if (event.type === 'assistant' ) {
console. log ( `[assistant] tokens: ${ event . message . usage ?. output_tokens }` )
} else if (event.type === 'result' ) {
console. log ( `[done] ${ event . subtype } in ${ event . duration_ms }ms` )
}
}
},
}
)
await sandbox. kill ()
Resume a session
Claude Code persists conversations that can be resumed with follow-up tasks using --resume.
JavaScript & TypeScript
Python
import { Sandbox } from 'e2b'
const sandbox = await Sandbox. create ( 'claude' , {
envs: { ANTHROPIC_API_KEY: process.env. ANTHROPIC_API_KEY },
timeoutMs: 600_000 ,
})
// Start a new session
const initial = await sandbox.commands. run (
`cd /home/user/repo && claude --dangerously-skip-permissions --output-format json -p "Analyze the codebase and create a refactoring plan"`
)
// Extract session ID from the JSON response
const response = JSON . parse (initial.stdout)
const sessionId = response.session_id
// Continue with a follow-up task
const followUp = await sandbox.commands. run (
`cd /home/user/repo && claude --dangerously-skip-permissions --resume ${ sessionId } -p "Now implement step 1 of the plan"` ,
{ onStdout : ( data ) => process.stdout. write (data) }
)
const diff = await sandbox.commands. run ( 'cd /home/user/repo && git diff' )
console. log (diff.stdout)
await sandbox. kill ()
Custom system prompt
Write a CLAUDE.md file into the sandbox for project context or use --system-prompt to provide task-specific instructions.
JavaScript & TypeScript
Python
import { Sandbox } from 'e2b'
const sandbox = await Sandbox. create ( 'claude' , {
envs: { ANTHROPIC_API_KEY: process.env. ANTHROPIC_API_KEY },
})
// Write project context
await sandbox.files. write ( '/home/user/repo/CLAUDE.md' , `
You are working on a Go microservice.
Always use structured logging with slog.
Follow the project's error handling conventions in pkg/errors.
` )
const result = await sandbox.commands. run (
`cd /home/user/repo && claude --dangerously-skip-permissions -p "Add a /healthz endpoint"`
)
console. log (result.stdout)
await sandbox. kill ()
Claude Code has built-in support for MCP . E2B provides an MCP gateway that gives Claude access to 200+ tools from the Docker MCP Catalog .
JavaScript & TypeScript
Python
import { Sandbox } from 'e2b'
const sandbox = await Sandbox. create ( 'claude' , {
envs: { ANTHROPIC_API_KEY: process.env. ANTHROPIC_API_KEY },
mcp: {
browserbase: {
apiKey: process.env. BROWSERBASE_API_KEY ,
projectId: process.env. BROWSERBASE_PROJECT_ID ,
},
},
})
const mcpUrl = sandbox. getMcpUrl ()
const mcpToken = await sandbox. getMcpToken ()
await sandbox.commands. run (
`claude mcp add --transport http e2b-mcp-gateway ${ mcpUrl } --header "Authorization: Bearer ${ mcpToken }"`
)
const result = await sandbox.commands. run (
`claude --dangerously-skip-permissions -p "Use browserbase to research E2B and summarize your findings"` ,
{ onStdout: console.log }
)
await sandbox. kill ()
Build a custom template
If you need to customize the environment (e.g. pre-install dependencies, add config files), build your own template on top of the pre-built claude template.
JavaScript & TypeScript
Python
// template.ts
import { Template } from 'e2b'
export const template = Template ()
. fromTemplate ( 'claude' )
JavaScript & TypeScript
Python
// build.ts
import { Template, defaultBuildLogger } from 'e2b'
import { template as claudeCodeTemplate } from './template'
await Template. build (claudeCodeTemplate, 'my-claude' , {
cpuCount: 2 ,
memoryMB: 2048 ,
onBuildLogs: defaultBuildLogger (),
})
Run the build script to create the template.
JavaScript & TypeScript
Python
MCP tools Connect Claude Code to 200+ MCP tools
Sandbox persistence Auto-pause, resume, and manage sandbox lifecycle
Git integration Clone repos, manage branches, and push changes