SandboxAgent instances inside isolated E2B sandboxes — giving your agents full filesystem, terminal, and network access in a secure environment.
To use E2B as the sandbox backend:
- Create a sandbox session with
E2BSandboxClient. - Build a
SandboxAgentwith your instructions and model. - Run the agent and pass the sandbox session through
RunConfig.
Install the dependencies
Install the OpenAI Agents SDK with the E2B extra to pull in the sandbox integration.Basic example
Create anE2BSandboxClient, start a session, and run a SandboxAgent inside it. The agent gets full access to the sandbox environment — it can run commands, read and write files, and inspect the workspace.
Create a session
Initialize theE2BSandboxClient and create a sandbox session. The pause_on_exit option keeps the sandbox available after the script finishes so you can inspect its state.
Build and run the agent
Define aSandboxAgent with a name, model, and instructions, then run it against the sandbox session using Runner.run. The result contains the agent’s final output.
Shut down
Always shut down the session when you’re done to release sandbox resources.Full example
The complete script that ties the steps above together.Build an app with multiple versions
A common pattern is to start from the same starter app and create multiple versions in separate sandboxes — useful when comparing a first pass with a polished revision, or generating live preview URLs for each version. Based on thehomepage_vite_basic_updated.ipynb notebook from the Agents SDK repo.
Define a manifest
AManifest describes the starter files your agent will work with. Each entry is a File with its content encoded as bytes. This lets you seed multiple sandboxes from the same baseline — useful when comparing different versions of an app.
Create a sandbox session
Create a sandbox session with the manifest, exposed ports for live previews, and internet access so the agent can install npm packages.Run the agent
Build aSandboxAgent with capabilities like ApplyPatch and Shell, then run it against the sandbox session.
Start a preview server
After the agent finishes, install dependencies, start the Vite dev server, and resolve the exposed port to get a live preview URL.Full example
The completerun_version() helper ties all the steps above together. Call it once per version to get isolated sandboxes with their own preview URLs. Based on the homepage_vite_basic_updated.ipynb notebook from the Agents SDK repo.
MCP-powered research agents
You can create sandboxes with MCP servers enabled, then connect the Agents SDK to the sandbox’s MCP gateway. This gives you an agent that can discover sources with search-oriented MCP servers, verify pages in a browser, and keep all of that execution inside the sandbox. The Agents SDK repo includes a concrete example indeep_research_mcp.py.
Configure MCP servers
Pass MCP server configurations when creating the sandbox session. This example enables Browserbase for browser automation and Exa for search.Connect to the MCP gateway
UseMCPServerStreamableHttp to connect to the sandbox’s MCP gateway. This gives the agent access to all the MCP servers you configured above.
Run the agent
Pass the MCP server to theSandboxAgent via mcp_servers. The agent can now discover and call tools from all configured MCP servers.
Full example
The complete script combining session creation, MCP gateway connection, and agent execution.Parallel sandbox workers
Use one coordinator agent to launch multiple specialized review or analysis lanes across separate sandboxes. Each lane runs in its own isolated environment, and the coordinator synthesizes the results into a single summary. The Agents SDK repo includes a concrete example infullstack_code_review_parallel.py. That example uses separate E2B-backed lanes for frontend review, backend review, and git tree review.
Define the agents
Create specializedSandboxAgent instances for each review lane, plus a regular Agent as the coordinator that will synthesize the results.
Run the lanes
Run each review agent against its own sandbox session. The lanes are independent and can run concurrently.Synthesize the results
Feed the findings from each lane into the coordinator agent to produce a single summary.Full example
The complete script defining agents, running parallel review lanes, and synthesizing results.Reference examples
The OpenAI Agents SDK repository includes several complete examples demonstrating E2B sandbox integration.Basic and updated app
Build and iterate on a Vite app across isolated sandboxes
MCP deep research
Research agent with Browserbase and Exa via MCP
Parallel code review
Multi-lane code review with a coordinator agent
E2B agents setup
Getting started notebook for E2B sandbox integration