---
title: "LangChain Deep Agents integration"
description: "Run LangChain Deep Agents on E2B. The langchain-e2b backend sends the agent's file tools and shell commands to an isolated sandbox, not your machine."
url: "https://e2b.dev/integrations/langchain-deepagents"
---

# LangChain Deep Agents

> Make an E2B sandbox the environment for a LangChain Deep Agent. With the langchain-e2b backend, the agent's file tools and shell commands run in the sandbox instead of on your machine.

Agent frameworks & SDKs · [All integrations](https://e2b.dev/integrations.md)

## About this integration

- **Maintained by:** E2B
- **How it works:** Sandbox backend for Deep Agents
- **Package:** langchain-e2b
- **Language:** Python
- **Upstream:** [langchain-ai/deepagents · ★ 31k](https://github.com/langchain-ai/deepagents)
- **Docs:** [docs.e2b.dev/agents/deep-agents](https://docs.e2b.dev/agents/deep-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 LangChain Deep Agents project.

1. Install deepagents, langchain-e2b and e2b using the project's package manager.
2. The sandbox 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.
3. Follow the Deep Agents guide at https://docs.e2b.dev/agents/deep-agents. Create a sandbox with Sandbox.create(), pass E2BSandbox(sandbox=sandbox) as the backend to create_deep_agent, and kill the sandbox when the agent is done.
4. Run one task and show me the output that came from the sandbox.
```

## Or set it up yourself

### 1. Install the packages

```bash
pip install deepagents langchain-e2b e2b
```

### 2. Set your API keys

```bash
export E2B_API_KEY="e2b_***"
export ANTHROPIC_API_KEY="sk-ant-***"
```

### 3. Create the agent on a sandbox

```python
from deepagents import create_deep_agent
from e2b import Sandbox
from langchain_e2b import E2BSandbox

sandbox = Sandbox.create(timeout=600)

agent = create_deep_agent(
    model="anthropic:claude-sonnet-5",
    system_prompt="You are a coding agent working in an isolated Linux sandbox.",
    backend=E2BSandbox(sandbox=sandbox),
)
```

### 4. Run a task

```python
result = agent.invoke({
    "messages": [{
        "role": "user",
        "content": "Create hello.py that prints 'Hello from E2B', run it, and show the output.",
    }]
})

print(result["messages"][-1].content)
sandbox.kill()
```

## What runs in the sandbox

The agent's built-in tools all run in an isolated sandbox, away from your machine.

- **Files:** ls, read_file, write_file, edit_file, glob and grep work on the sandbox filesystem.
- **Shell:** The execute tool runs shell commands inside the sandbox.
- **Lifetime:** You create the sandbox and kill it when done. In dcode, the sandbox is created on start and deleted on exit.
- **Template:** Pass a custom template to Sandbox.create() to preinstall the languages and tools your agent needs.

## More agent frameworks

Other frameworks that run their tools on E2B.

- [LangGraph](https://e2b.dev/integrations/langgraph.md): Run code from LangGraph plan-and-execute agents in an E2B sandbox.
- [CrewAI](https://e2b.dev/integrations/crewai.md): Give CrewAI agents E2B tools for shell commands, Python, and files with the crewai-tools[e2b] extra.
- [Mastra](https://e2b.dev/integrations/mastra.md): Give Mastra agents an E2B workspace or a full desktop with @mastra/e2b and @mastra/e2b-desktop.

## Links

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