Learning resourcesReviewed · E2B

E2B OpenAI Agents API guide

This E2B guide shows developers how to give OpenAI Agents API sessions sandboxed command execution and file editing, but it requires preview access and ongoing sandbox upkeep. It covers an application-managed workbench and a webhook-managed Python example with one worker sandbox per session.

Researched 25 Nov 2026

In short.

This E2B guide helps developers connect OpenAI Agents API sessions to execution sandboxes, but they need preview access and must manage sandbox lifetimes. OpenAI hosts the agent and session state; E2B runs its shell commands and file edits. The detailed quick start uses OpenAI webhooks to coordinate a controller sandbox and a dedicated worker for each session. An alternative workbench provides a streaming chat interface and workspace viewer. The page explains credential separation, reconnection problems and cleanup, but does not establish prices, reuse rights or production reliability. No commands or software were run.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage is the complete captured selected-page.txt from [https://docs.e2b.dev/agents/openai-agents-api.md]. It includes both provisioning approaches, the preview notice, key exposure warning, setup, examples, lifecycle rules and troubleshooting. The documentation index, linked repositories, OpenAI documentation and related E2B pages are excluded. The original source address and captured evidence identity are retained. No commands or software were run; example responses, timings, isolation and lifecycle behavior remain untested.

The overview

Identity

The resource is E2B's integration guide at [https://docs.e2b.dev/agents/openai-agents-api.md]. It teaches how to attach an E2B execution environment to the preview OpenAI Agents API, while the agent and its session state remain in OpenAI's cloud.

The page explicitly distinguishes the Agents API from the open-source OpenAI Agents SDK. Its main quick start covers webhook-managed provisioning; it also introduces an application-managed Agents API Workbench.

Assessment

This is a concrete starting point for developers who already have Agents API preview access and want commands and file changes to happen in E2B. Its useful detail is operational: key permissions, webhook registration, worker reuse, timeout behavior and specific failure symptoms.

The guide requires more than obtaining API keys and sending a request. Developers must keep a controller available, handle changes to its webhook URL and clean up workers separately from OpenAI sessions. Production reliability, scaling capacity and isolation strength are not established by the page.

Users

The guide suits Python developers and platform teams integrating cloud-hosted agents with a separate command execution environment. The webhook approach is particularly relevant when the application should communicate only with the Agents API and avoid importing the E2B SDK.

The workbench offers a browser interface for initial exploration. The webhook instructions assume comfort with terminal commands, environment files, API key scopes and webhook configuration, so beginners may need background knowledge in those areas.

Capabilities

The documented integration provides a dedicated worker sandbox for each session, repeated turns in the same workspace and pause/resume behavior that retains files. Failed sessions cause their workers to be paused for inspection. Controller and executor logs support troubleshooting.

The application-managed workbench uses a Flask backend and React frontend. It provides a streaming transcript and a live /workspace file viewer, with one executor sandbox per chat.

Using it

Requirements

Prerequisites include an E2B API key, an OpenAI project with Agents API access and uv. The scripts declare their dependencies inline. The agent_api_sdk Python package comes from the preview repository at [https://github.com/OpenAI-Early-Access/agents-api-python-preview], rather than PyPI. The setup also uses Git and the E2B CLI.

The application key needs Responses → Write. A separate executor key must have only List models → Read and belong to the same organization, project and user or service account as the application key. In the documented design, only the executor key enters a worker, as CODEX_API_KEY. Agent-generated code can read that credential, so the page instructs developers to keep the application key out of workers.

Mechanism

In the webhook approach, a controller is a coordinating sandbox that receives OpenAI events. When input requires execution, agent.session.action_required prompts it to create a worker from a prepared template and launch codex exec-server. That executor connects outward to OpenAI and runs the turn in /workspace.

The controller manages sessions for one configured agent. Follow-up turns reuse the session's worker. An agent.session.failed event causes the controller to pause the worker. In the application-managed approach, the application uses the E2B SDK to create, connect and stop sandboxes and starts the executor itself.

Setup

The short workbench path starts with e2b sandbox create openai-agents-api-python-sdk. Once ready, its terminal prints a single-use UI link where the developer supplies OpenAI and E2B keys and starts a chat.

For webhook setup, the guide uses the cookbook's examples/openai-agents-api-python-sdk-webhook-managed directory. Its gitignored .env contains OPENAI_API_KEY, OPENAI_EXECUTOR_API_KEY, E2B_API_KEY, OPENAI_AGENT_ID and OPENAI_WEBHOOK_SECRET. The sequence is to create an agent, build the worker template, deploy the controller, register agent.session.action_required and agent.session.failed in the application key's OpenAI project, then redeploy with the signing secret.

The page estimates about three minutes for a template build and one minute for controller deployment; these are documentation estimates. Templates need rebuilding after changing CODEX_VERSION. Variables already exported in the shell override values supplied through uv run --env-file, which can cause an unexpected E2B key to be used.

Example

The example starts a session with the request to write hello to /workspace/hello.txt and read it. The client prints a session_id, which a follow-up request uses to read the same file again through the same worker.

The page estimates roughly 40 seconds for a new session and describes follow-ups as starting immediately. These are source descriptions, not measured results. Deleting the example session must be followed by separately locating and killing its E2B worker.

Assessment & evidence

Limitations

The Agents API is in preview and requires project access. The controller has a one-hour timeout, and OpenAI traffic cannot wake it after it is paused or expired. Redeployment extends a surviving controller's timeout; replacing an expired controller produces a new URL that must be entered in the OpenAI webhook configuration.

Workers have a 30-minute timeout refreshed on reconnect. Pausing retains files, but killing a worker causes replacement with a fresh sandbox without the previous files. Session deletion does not clean up its sandbox, including a paused worker.

The page documents a reconnection gap: input within about three minutes of pausing or killing a worker may arrive before OpenAI notices the executor is offline. No reconnect webhook then fires, and the turn can run without shell access. The session may continue declining shell use; the documented remedies are waiting or starting a new session.

Reasoning

The main design tradeoff is where sandbox orchestration lives. Application-managed provisioning puts executor startup and agent events in the application. Webhook-managed provisioning keeps the E2B SDK out of that application but adds a separately deployed controller whose availability must be maintained.

OpenAI session state and E2B filesystem state have separate lifecycles. Keeping a session ID therefore does not guarantee that its earlier files survive a worker replacement. Applications that depend on those files need to account for that distinction.

Alternatives

The page recommends the application-managed Workbench as the first entry point and points to its example at [https://github.com/e2b-dev/e2b-cookbook/tree/main/examples/openai-agents-api-python-sdk]. It directs applications needing events in their own process, a live UI or function tools toward application-managed provisioning.

The webhook example is at [https://github.com/e2b-dev/e2b-cookbook/tree/main/examples/openai-agents-api-python-sdk-webhook-managed]. Developers seeking the open-source agent framework are directed to [https://docs.e2b.dev/agents/openai-agents-sdk.md]. These linked resources are outside the assessed page, so their implementation details and comparative performance are unknown.

Evidence

E2B's page provides integration instructions, expected health responses, lifecycle rules, log locations and troubleshooting symptoms. It contains no benchmark data or independent validation of isolation or reliability.

The commands, example outputs and timing estimates are documentation claims. No commands were executed, and compatibility, performance and live service availability were not tested. Linked repositories and other documentation pages provide no additional assessed evidence here.

Access & freshness

Costs

Prices, billing units, free allowances and total operating costs are unknown from this page. A budget would require the applicable OpenAI and E2B pricing.

The documented architecture includes a controller and workers that remain running between turns. Deleting an OpenAI session does not stop its worker. Those lifecycle details matter when estimating resource use, but the page does not explain how running or paused sandboxes are charged.

Rights

The page supplies no license or redistribution terms for its documentation or examples. Licenses for the linked repositories, applicable service terms and rights in generated files are not established by this evidence.

Permission to copy, modify, redistribute or commercially reuse the materials cannot be determined from this page alone.

Freshness

The page was captured on 2026-11-25 at 21:08:02.043 UTC. Its text identifies the Agents API as a preview but supplies no publication date, update date or fixed SDK or Codex version.

The instruction to rebuild worker templates after changing CODEX_VERSION makes version matching an ongoing requirement. Compatibility with later package or service changes is unknown.

Actions

Confirm preview entitlement and the required key scopes before setup. Start with the workbench for an interactive introduction. For webhook provisioning, verify the agent ID, register the webhook in the application key's project and redeploy with its signing secret. The documented health checks expect an ok response from /health and an Invalid signature response to an unsigned empty webhook request.

Plan controller renewal, webhook URL updates and separate session and worker cleanup. Inspect paused workers when needed, then kill them when finished. Remove the OpenAI webhook before permanently killing the controller. Obtain current pricing and applicable reuse terms before making budget or redistribution commitments.

Evidence for this report

selected-page.txtselected · checked 2026-11-25