Skip to main content

Agent frameworks & SDKs

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.

Maintained by
OpenAI
How it works
Built into openai-agents
Package
openai-agents[e2b]
Language
Python

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

  1. 1.Install the Agents SDK with the e2b extra ("openai-agents[e2b]") using the project's package manager.
  2. 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. 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. 4.Run the agent once and show me the output that came from the sandbox.

Or set it up yourself

  1. 1. Install the SDK with the E2B extra

    pip install openai-agents[e2b]
  2. 2. Set your API keys

    export OPENAI_API_KEY="..."
    export E2B_API_KEY="..."
  3. 3. Create a sandbox session

    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. 4. Run a SandboxAgent in it

    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()

Security

What runs in the sandbox

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

  • CodeCommands, file reads and writes the SandboxAgent makes, executed in the E2B session.
  • WorkspaceSeed the sandbox with a Manifest of starter files, and expose ports to get live preview URLs.
  • Lifetimetimeout bounds the session. pause_on_exit=True keeps the sandbox for inspection; session.shutdown() releases it.
  • MCPPass MCP server configs when you create the session, and the agent reaches them through the sandbox's MCP gateway.

3B+ sandboxes started

Give every agent a machine