Skip to main content

Coding agents

Claude Code

Run Claude Code in its own sandbox with a real filesystem, terminal and git. The prebuilt claude template has it installed, so it can work unattended and you collect the diff.

Maintained by
E2B
How it works
Prebuilt claude sandbox template
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

Run Claude Code in an E2B sandbox from this project.

  1. 1.Install the e2b SDK using the project's package manager.
  2. 2.The SDK needs the E2B_API_KEY environment variable, and Claude Code needs ANTHROPIC_API_KEY. If E2B_API_KEY isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode either key.
  3. 3.Follow the Claude Code guide at https://docs.e2b.dev/agents/claude-code: create a sandbox from the claude template, pass ANTHROPIC_API_KEY in envs, and run claude -p with --dangerously-skip-permissions and a command timeout of 0. Kill the sandbox in a finally block.
  4. 4.Run one task and show me the output that came from the sandbox.

Or set it up yourself

  1. 1. Install the E2B SDK

    npm init -y && npm pkg set type=module
    npm install e2b
    npm install -D tsx
  2. 2. Set your API keys

    export E2B_API_KEY="e2b_..."
    export ANTHROPIC_API_KEY="..."
  3. 3. Run Claude Code headless

    import { Sandbox } from 'e2b'
    
    const apiKey = process.env.ANTHROPIC_API_KEY
    if (!apiKey) throw new Error('Set ANTHROPIC_API_KEY')
    
    const sandbox = await Sandbox.create('claude', {
      envs: { ANTHROPIC_API_KEY: apiKey },
    })
    
    try {
      const result = await sandbox.commands.run(
        `claude --dangerously-skip-permissions -p "Create a hello world HTTP server in Go"`,
        { cwd: '/home/user', timeoutMs: 0 }
      )
      console.log(result.stdout)
    } finally {
      await sandbox.kill()
    }
  4. 4. Work on a repository

    await sandbox.commands.run(
      'git clone --depth 1 https://github.com/e2b-dev/claude-code-fastapi.git /home/user/repo'
    )
    
    await sandbox.commands.run(
      `claude --dangerously-skip-permissions -p "Add error handling to all API endpoints"`,
      { cwd: '/home/user/repo', timeoutMs: 0 }
    )
    
    const diff = await sandbox.commands.run('git diff', { cwd: '/home/user/repo' })
    console.log(diff.stdout)

Security

What runs in the sandbox

Claude Code and every command it runs live in the sandbox, away from your machine and its files.

  • AgentThe claude CLI, auto-approving its own tool calls. The sandbox contains them, so it can't touch your host.
  • FilesThe repo you clone and everything Claude Code writes. Read results back with files.read() or git diff.
  • SessionsConversations persist in the sandbox. Pass -⁠-⁠resume with the session ID to send a follow-up task.
  • NetworkInternet access is on by default. Restrict outbound traffic with network rules for untrusted input or secrets.

3B+ sandboxes started

Give every agent a machine