Skip to main content

Agent platforms

Claude Managed Agents

Claude runs the agent loop, and the tool calls run in sandboxes you own. A webhook router on E2B gives each session its own worker sandbox.

Maintained by
E2B
How it works
Self-hosted environment via webhooks
Template
E2B/claude-managed-agents-webhooks
Package
e2b + anthropic
Language
Python, TypeScript

Set it up

Get started

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

Paste this into your coding agent

Add E2B sandboxes to this Claude Managed Agents project.

  1. 1.Install e2b and the Anthropic SDK (anthropic for Python, @anthropic-ai/sdk for TypeScript) using the project's package manager.
  2. 2.The code 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 ANTHROPIC_API_KEY, ANTHROPIC_ENVIRONMENT_ID, ANTHROPIC_ENVIRONMENT_KEY and ANTHROPIC_AGENT_ID from the Claude Console the same way.
  3. 3.Follow the Claude Managed Agents guide at https://docs.e2b.dev/agents/claude-managed-agents: start the E2B/claude-managed-agents-webhooks template with auto-resume, write its config, and print the webhook URL. Have me register it in the Claude Console for session.status_run_started, then write the signing key (ANTHROPIC_WEBHOOK_SIGNING_KEY) into the same sandbox.
  4. 4.Create a session, send one message that runs a shell command, and show me Claude's answer and the worker log from the sandbox.

Or set it up yourself

  1. 1. Install the SDKs

    pip install e2b anthropic
  2. 2. Set your keys

    export E2B_API_KEY="e2b_..."
    export ANTHROPIC_API_KEY="..."
    export ANTHROPIC_ENVIRONMENT_ID="..."
    export ANTHROPIC_ENVIRONMENT_KEY="..."
    export ANTHROPIC_AGENT_ID="..."
    # after you register the webhook in step 4
    export ANTHROPIC_WEBHOOK_SIGNING_KEY="..."
  3. 3. Start the webhook sandbox

    import os
    from e2b import Sandbox
    
    sandbox = Sandbox.create(
        "E2B/claude-managed-agents-webhooks",
        lifecycle={"on_timeout": "pause", "auto_resume": True},
    )
    
    config = "/opt/anthropic-managed-agents-js/config"
    sandbox.files.write(f"{config}/e2b-api-key", f"{os.environ['E2B_API_KEY']}\n")
    sandbox.files.write(f"{config}/anthropic-api-key", f"{os.environ['ANTHROPIC_API_KEY']}\n")
    sandbox.files.write(f"{config}/anthropic-environment-id", f"{os.environ['ANTHROPIC_ENVIRONMENT_ID']}\n")
    sandbox.files.write(f"{config}/anthropic-environment-key", f"{os.environ['ANTHROPIC_ENVIRONMENT_KEY']}\n")
    
    print(f"Webhook URL: https://{sandbox.get_host(8000)}/webhook")
  4. 4. Register the webhook, then start a session

    from anthropic import Anthropic as Claude
    
    sandbox.files.write(
        "/opt/anthropic-managed-agents-js/config/anthropic-webhook-signing-key",
        f"{os.environ['ANTHROPIC_WEBHOOK_SIGNING_KEY']}\n",
    )
    
    client = Claude(api_key=os.environ["ANTHROPIC_API_KEY"])
    
    session = client.beta.sessions.create(
        agent=os.environ["ANTHROPIC_AGENT_ID"],
        environment_id=os.environ["ANTHROPIC_ENVIRONMENT_ID"],
        title="E2B webhook smoke",
    )
    
    client.beta.sessions.events.send(
        session.id,
        events=[{
            "type": "user.message",
            "content": [{
                "type": "text",
                "text": "Use bash to echo webhook-smoke-ok. Answer only with that text.",
            }],
        }],
    )

Security

What runs in the sandbox

Claude decides what to do. The filesystem, tools, network and logs live in E2B sandboxes you own.

  • ToolsEvery tool call runs in a worker sandbox with /mnt/session as its workdir. Claude's reasoning loop does not.
  • StateEach session gets its own worker. Follow-up turns reconnect to it and reuse the same /mnt/session files.
  • LifetimeThe router starts workers with auto-resume and pause-on-timeout, so idle sessions pause instead of losing state.
  • RoutingThe webhook sandbox verifies Claude's webhooks with your signing key and keeps the session-to-sandbox assignments.

3B+ sandboxes started

Give every agent a machine