Using CoAI Sandbox with the OpenAI Agents SDK
The OpenAI Agents SDK for Python can run an agent's code and shell tools in an E2B sandbox (the e2b extra). Because CoAI
Sandbox is compatible with the E2B SDK, the same integration runs on CoAI Sandbox: the Agents SDK creates the sandbox through
the official e2b package, which reads the same two environment variables as everywhere else. One option must change:
the sandbox's timeout action (step 3).
-
Install the Agents SDK with its E2B extra (a version that has it, 0.14.0 or later):
pip install 'openai-agents[e2b]' -
Set the variables of the quickstart, plus your model provider's key for the Agents SDK:
export E2B_API_KEY=ack_... # your CoAI Sandbox API key export E2B_DOMAIN=sandbox.coaiwork.com # CoAI Sandbox instead of E2B export OPENAI_API_KEY=... # the model key the Agents SDK uses -
Set
on_timeout="kill"in theE2BSandboxClientOptionsthat create the sandbox, then run your agent as the Agents SDK's documentation describes:from agents.extensions.sandbox import E2BSandboxClientOptions, E2BSandboxType options = E2BSandboxClientOptions( sandbox_type=E2BSandboxType.E2B, timeout=300, on_timeout="kill", # required on CoAI Sandbox: the default "pause" is refused )Why: the Agents SDK's default is
on_timeout="pause"withauto_resume, so it creates the sandbox with auto-pause and auto-resume. CoAI Sandbox does not offer pausing yet (compatibility page) and refuses that create with 400unsupported_feature. Withon_timeout="kill", E2B's own default, the sandbox ends when its timeout passes, like every CoAI Sandbox sandbox. For the same reason keeppause_on_exitoff (its default). The Agents SDK's E2B example (examples/sandbox/extensions/e2b_runner.pyin its repository) does not seton_timeout, so it fails as it is: addon_timeout="kill"to both of itsE2BSandboxClientOptions(...). Nothing else in the code refers to CoAI Sandbox.
What to keep in mind:
- The sandboxes count against your level's limits and are charged like any other (pricing page). Let the agent kill its sandbox when the run ends, or give it a short timeout.
- For now the sandbox reaches only the allowlist of the network page at every level; tools that fetch arbitrary web pages do not work yet (open internet access for A1 and A2 is planned).
- The model calls of the agent go from your program to your model provider, not through CoAI Sandbox, and are paid there.