Sign in

Run an OpenAI Agents SDK agent in a sandbox

Updated

The openai-agents-prized package is a sandbox client for the OpenAI Agents SDK: a SandboxAgent's commands and file edits run in a Prized sandbox, which is deleted when the run ends.

On this page6

A SandboxAgent runs its tools through the sandbox client in its run config. PrizedSandboxClient from openai-agents-prized is one: pass it as SandboxRunConfig(client=...), and the agent's commands and file edits run in a Prized sandbox, a Firecracker microVM billed per second that can pause with its memory between runs.

1. Install the package and export your keys

python3 -m venv .venv && . .venv/bin/activate
pip install openai-agents-prized
export PRIZED_API_KEY=dcp_…
export OPENAI_API_KEY=…

The first line makes a virtual environment, since Ubuntu, Debian and Homebrew refuse pip install into the system Python (if it says ensurepip is not available, run sudo apt install python3-venv first; on Windows, run py -m venv .venv, then .venv\Scripts\activate).

It needs Python 3.10 or later and installs the OpenAI Agents SDK (openai-agents). For the Prized key, Open Sandboxes and choose Create API key (new to Prized, it signs you up with the free credit, no card), or make one on the API keys page with Full access, or Custom with Sandboxes: Write.

2. Run an agent

agent.py
import asyncio

from agents import Runner
from agents.run import RunConfig
from agents.sandbox import SandboxAgent, SandboxRunConfig
from openai_agents_prized import PrizedSandboxClient, PrizedSandboxClientOptions

agent = SandboxAgent(name="coder", instructions="Work in the sandbox with your tools.")
sandbox = SandboxRunConfig(client=PrizedSandboxClient(), options=PrizedSandboxClientOptions(vcpu=2, memory_mb=4096))
task = "Write fizzbuzz.py, run it for 15, and show me the output."
result = asyncio.run(Runner.run(agent, task, run_config=RunConfig(sandbox=sandbox)))
print(result.final_output)
python agent.py

The agent's exec_command, write_stdin and apply_patch tools run in the sandbox as the user prized in /home/prized/work, and the sandbox is deleted when the run ends. It bills per second like any other (Billing: Sandboxes).

Options

PrizedSandboxClientOptions takes the fields of a create: template (prized-agent-v1 adds Claude Code and Codex), vcpu, memory_mb, disk_gb, env_vars, labels, auto_pause_min, auto_delete_min and max_runtime_min. Options written as a dict or JSON, for the SDK's BaseSandboxClientOptions.parse, name this client with "type": "prized"; the constructor sets it for you.

  • Pause instead of delete. pause_on_exit=True pauses the sandbox at the end of a run, keeping memory and disk for the price of storage. A run resumed from its saved state continues in the same sandbox; without it, the resumed run gets a new sandbox with the workspace restored. If the pause fails, the sandbox is left running rather than deleted, and client.delete(session) raises so you can try again.
  • Moving from Runloop. Replace RunloopSandboxClient and its options with PrizedSandboxClient and PrizedSandboxClientOptions; the agent stays the same. Runloop's blueprint_name becomes template, and metadata becomes labels.

Common questions

Which sandbox providers work with the OpenAI Agents SDK?

Unix-local, on your own machine, needs no extra; Docker, E2B, Modal, Daytona, Cloudflare, Vercel and Blaxel are extras of openai-agents, and Databricks' comes in databricks-openai (OpenAI: Sandbox clients). Other providers ship their own package that plugs into SandboxRunConfig(client=...), as Prized does with openai-agents-prized.

Limits

  • No root. No sudo or apt (Inside a sandbox), so manifest users other than prized, manifest groups, and mounts are refused before a sandbox is created.
  • No exposed ports. The client exposes none to the SDK. A port in the sandbox answers at its own https URL for your API key, or for a token once the workspace has paid in (Preview a port).
  • Commands. One that outlives exec_command's wait keeps running until it exits, its timeout passes, or the run ends, and the agent checks on it or types into it with write_stdin. Output is kept up to 4 MiB a stream.
  • Failures. A failed or cancelled create deletes its sandbox, and a failed resume pauses the sandbox again. A lost answer is checked against the sandbox's state, so a paused sandbox is never deleted by mistake. A sandbox paused during a run (auto_pause_min) is resumed by the next command; once the run has paused or deleted it, nothing the run sent late wakes it.
  • Run time. 24 hours of running by default, up to 7 days with max_runtime_min (Run time). On the free tier: 60 minutes, 2 vCPU and 4 GB a sandbox, and 10 sandboxes at once.
  • Keys. Code in the sandbox, the model's included, can read what you pass in env_vars. Keep your Prized key out of it.

A refusal from the API raises PrizedAPIError, whose code is the API's (Errors). Questions: .