Skip to main content
For a complete guide on running Claude Code in E2B sandboxes — including working with repositories, streaming output, and connecting MCP tools — see the Agents in Sandbox: Claude Code guide.
// template.ts
import { Template } from 'e2b'

export const template = Template()
  .fromNodeImage('24')
  .aptInstall(['curl', 'git', 'ripgrep'])
  // Claude Code will be available globally as "claude"
  .npmInstall('@anthropic-ai/claude-code@latest', { g: true })

# template.py
from e2b import Template

template = (
    Template()
    .from_node_image("24")
    .apt_install(["curl", "git", "ripgrep"])
    # Claude Code will be available globally as "claude"
    .npm_install("@anthropic-ai/claude-code@latest", g=True)
)
// build.ts
import { Template, defaultBuildLogger } from 'e2b'
import { template as claudeCodeTemplate } from './template'

Template.build(claudeCodeTemplate, 'claude-code', {
  cpuCount: 1,
  memoryMB: 1024,
  onBuildLogs: defaultBuildLogger(),
})
# build.py
from e2b import Template, default_build_logger
from .template import template as claudeCodeTemplate

Template.build(claudeCodeTemplate, 'claude-code',
    cpu_count=1,
    memory_mb=1024,
    on_build_logs=default_build_logger(),
)
// sandbox.ts
import { Sandbox } from 'e2b'

const sbx = await Sandbox.create('claude-code', {
  envs: {
    ANTHROPIC_API_KEY: '<your api key>',
  },
})

console.log('Sandbox created', sbx.sandboxId)

// Print help for Claude Code
// const result = await sbx.commands.run('claude --help')
// console.log(result.stdout)

// Run a prompt with Claude Code
const result = await sbx.commands.run(
  `claude --dangerously-skip-permissions -p 'Create a hello world index.html'`,
  { timeoutMs: 0 }
)

console.log(result.stdout)

sbx.kill()
# sandbox.py
from e2b import Sandbox

sbx = Sandbox(
    'claude-code',
    envs={
        'ANTHROPIC_API_KEY': '<your api key>',
    },
)
print("Sandbox created", sbx.sandbox_id)

# Print help for Claude Code
# result = sbx.commands.run('claude --help')
# print(result.stdout)

# Run a prompt with Claude Code
result = sbx.commands.run(
    "claude --dangerously-skip-permissions -p 'Create a hello world index.html'",
    timeout=0,
)
print(result.stdout)

sbx.kill()