---
title: "Claude Managed Agents integration"
description: "Run Claude Managed Agents tool calls in E2B sandboxes you own. A webhook router gives each session its own persistent worker sandbox."
url: "https://e2b.dev/integrations/claude-managed-agents"
---

# 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.

Agent platforms · [All integrations](https://e2b.dev/integrations.md)

## About this integration

- **Maintained by:** E2B
- **How it works:** Self-hosted environment via webhooks
- **Template:** E2B/claude-managed-agents-webhooks
- **Package:** e2b + anthropic
- **Language:** Python, TypeScript
- **Example:** [e2b-cookbook/anthropic-managed-agents](https://github.com/e2b-dev/e2b-cookbook/tree/main/examples/anthropic-managed-agents)

## Get started

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

### Paste this into your coding agent

```text
Add E2B sandboxes to this Claude Managed Agents project.

1. Install e2b and the Anthropic SDK (anthropic for Python, @anthropic-ai/sdk for TypeScript) using the project's package manager.
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. 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. 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. Install the SDKs

```bash
pip install e2b anthropic
```

### 2. Set your keys

```bash
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. Start the webhook sandbox

```python
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. Register the webhook, then start a session

```python
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.",
        }],
    }],
)
```

## What runs in the sandbox

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

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

## More agent platforms

Other hosted agent APIs that run their tools on E2B.

- [OpenAI Agents API](https://docs.e2b.dev/agents/openai-agents-api): Pick E2B as the execution environment for OpenAI's Agents API, app-managed or webhook-managed.
- [Gemini Managed Agents](https://docs.e2b.dev/agents/gemini-managed-agents): Run the file and shell tools of a Gemini API managed agent in your own E2B sandbox.
- [Cursor cloud agents](https://docs.e2b.dev/agents/cursor): Run Cursor's self-hosted cloud agents on E2B dispatcher and worker sandboxes.

## Links

- [Get API key](https://console.e2b.dev/?tab=keys)
- [Read the docs](https://docs.e2b.dev/agents/claude-managed-agents)
- [E2B documentation](https://docs.e2b.dev)
