---
title: "CrewAI integration"
description: "Give CrewAI agents an isolated E2B sandbox for running Python. The native E2BPythonTool runs agent-generated code in the sandbox, not on your machine."
url: "https://e2b.dev/integrations/crewai"
---

# CrewAI

> Give CrewAI agents an isolated sandbox for running Python. The native E2BPythonTool runs the code your agents write in E2B, not on your machine.

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

## About this integration

- **Maintained by:** CrewAI
- **How it works:** Built into crewai-tools
- **Package:** crewai-tools[e2b]
- **Language:** Python
- **Upstream:** [crewAIInc/crewAI · ★ 61k](https://github.com/crewAIInc/crewAI)
- **Example:** [e2b-cookbook/crewai-python](https://github.com/e2b-dev/e2b-cookbook/tree/main/examples/crewai-python)

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

1. Install crewai-tools with the e2b extra ("crewai-tools[e2b]") using the project's package manager.
2. The tool 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 CrewAI guide at https://docs.e2b.dev/agents/crewai and give my agents an E2BPythonTool, so the Python they write runs in an E2B sandbox. Close the tool in a finally block.
4. Run one task and show me the output that came from the sandbox.
```

## Or set it up yourself

### 1. Install the E2B tools

```bash
pip install "crewai-tools[e2b]" python-dotenv
```

### 2. Set your API keys

```bash
export E2B_API_KEY="e2b_..."
export OPENAI_API_KEY="..."
```

### 3. Give the tool to an agent

```python
from crewai import Agent, Crew, Task
from crewai_tools import E2BPythonTool

python_tool = E2BPythonTool(persistent=True, sandbox_timeout=600)

analyst = Agent(
    role="Data Analyst",
    goal="Use sandboxed Python to produce accurate analysis",
    backstory="You verify every answer by running code in an E2B sandbox.",
    tools=[python_tool],
)
```

### 4. Run your crew

```python
task = Task(
    description="Generate 10,000 random integers and return their mean and p95.",
    expected_output="A JSON object with the statistics.",
    agent=analyst,
)

try:
    print(Crew(agents=[analyst], tasks=[task]).kickoff())
finally:
    python_tool.close()
```

## What runs in the sandbox

The code your agents write runs in an isolated sandbox, away from the machine running CrewAI.

- **Code:** Python the agent writes, executed by E2BPythonTool in an E2B Code Interpreter sandbox.
- **State:** A new sandbox per tool call by default. persistent=True keeps imports and variables between calls.
- **Lifetime:** sandbox_timeout bounds how long the sandbox lives. Call close() in finally to shut it down.
- **Secrets:** Your API keys stay with CrewAI on your machine unless you pass them into the sandbox.

## More agent frameworks

Other frameworks that run their tools on E2B.

- [LangChain Deep Agents](https://e2b.dev/integrations/langchain-deepagents.md): Back LangChain Deep Agents with an E2B sandbox through the langchain-e2b package.
- [Hugging Face smolagents](https://github.com/huggingface/smolagents): Set executor_type="e2b" and smolagents runs every code action in a sandbox.
- [Vercel AI SDK](https://e2b.dev/integrations/vercel-ai-sdk.md): Give Vercel AI SDK agents sandbox tools with @e2b/ai-sdk-sandbox. Experimental for AI SDK 7.

## Links

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