---
title: "OpenAI Agents SDK integration"
description: "Run OpenAI Agents SDK sandbox agents in isolated E2B sandboxes with the built-in E2BSandboxClient: a full filesystem, terminal and network per agent."
url: "https://e2b.dev/integrations/openai-agents-sdk"
---

# OpenAI Agents SDK

> Run OpenAI Agents SDK sandbox agents in E2B. The SDK's built-in E2BSandboxClient gives each SandboxAgent a filesystem, terminal and network in an isolated sandbox.

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

## About this integration

- **Maintained by:** OpenAI
- **How it works:** Built into openai-agents
- **Package:** openai-agents[e2b]
- **Language:** Python
- **Upstream:** [openai/openai-agents-python · ★ 31k](https://github.com/openai/openai-agents-python)
- **Example:** [e2b-cookbook/openai-agents-sdk](https://github.com/e2b-dev/e2b-cookbook/tree/main/examples/openai-agents-sdk)

## 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 OpenAI Agents SDK project.

1. Install the Agents SDK with the e2b extra ("openai-agents[e2b]") using the project's package manager.
2. The sandbox client 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 OpenAI Agents SDK guide at https://docs.e2b.dev/agents/openai-agents-sdk. Create a session with E2BSandboxClient, run a SandboxAgent against it through RunConfig(sandbox=SandboxRunConfig(session=session)), and shut the session down in a finally block.
4. Run the agent once and show me the output that came from the sandbox.
```

## Or set it up yourself

### 1. Install the SDK with the E2B extra

```bash
pip install openai-agents[e2b]
```

### 2. Set your API keys

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

### 3. Create a sandbox session

```python
from agents.extensions.sandbox import (
    E2BSandboxClient,
    E2BSandboxClientOptions,
    E2BSandboxType,
)

client = E2BSandboxClient()
session = await client.create(
    options=E2BSandboxClientOptions(
        sandbox_type=E2BSandboxType.E2B,
        timeout=900,
        pause_on_exit=True,
    )
)
```

### 4. Run a SandboxAgent in it

```python
from agents import ModelSettings, Runner
from agents.run import RunConfig
from agents.sandbox import SandboxAgent, SandboxRunConfig

agent = SandboxAgent(
    name="Workspace Inspector",
    model="gpt-5.4",
    instructions="Inspect the workspace, explain what files exist, and summarize the project.",
    model_settings=ModelSettings(tool_choice="required"),
)

try:
    result = await Runner.run(
        agent,
        "Look around the workspace and summarize what you find.",
        run_config=RunConfig(sandbox=SandboxRunConfig(session=session)),
    )
    print(result.final_output)
finally:
    await session.shutdown()
```

## What runs in the sandbox

Each SandboxAgent works in its own isolated sandbox, away from the machine running the SDK.

- **Code:** Commands, file reads and writes the SandboxAgent makes, executed in the E2B session.
- **Workspace:** Seed the sandbox with a Manifest of starter files, and expose ports to get live preview URLs.
- **Lifetime:** timeout bounds the session. pause_on_exit=True keeps the sandbox for inspection; session.shutdown() releases it.
- **MCP:** Pass MCP server configs when you create the session, and the agent reaches them through the sandbox's MCP gateway.

## More agent frameworks

Other frameworks that run their tools on E2B.

- [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.
- [CrewAI](https://e2b.dev/integrations/crewai.md): Give CrewAI agents E2B tools for shell commands, Python, and files with the crewai-tools[e2b] extra.
- [Pydantic AI](https://e2b.dev/integrations/pydantic-ai.md): Run Pydantic AI agent tools in E2B through the pydantic-ai-harness E2B sandbox.

## Links

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