Best sandbox · OpenAI Agents SDK
The best sandbox for the OpenAI Agents SDK
Updated
An OpenAI Agents SDK agent that writes and runs code needs somewhere to run it that is not your process: a machine with its own kernel, a closed network, no keys inside, and a cheap reset. kosa8's Python SDK ships sandbox_tools() for the Agents SDK, which gives the agent shell, code, file and git tools that all run in one kosa8 microVM. If you use the SDK's own sandbox clients instead, kosa8 also answers as a local Docker host.
01What an Agents SDK agent needs from a sandbox
Agents built with the Agents SDK call function tools you register. A tool that runs model-written code is the riskiest one you will give it: the code can read whatever the process can read and reach whatever the network allows.
The sandbox therefore needs to hold the code, its files and its processes away from the host, to start closed and open only the hosts a task needs, and to be fast enough to create per conversation or per task. For evals and best-of-N runs it helps if a prepared machine can be copied rather than rebuilt.
02Checklist for choosing one
- Ready-made tools for the SDK. Function tools you can pass straight to
Agent(tools=...). - Kernel-level isolation. A microVM or VM rather than a process or a shared-kernel container.
- Default-deny network. Allow-listed hosts, enforced outside the guest.
- Persistent workspace and shell.
cdandexportthat carry over between tool calls. - Time limits. A hung command ends with a timeout instead of stalling the run.
- Copies and resets. Fork a prepared sandbox, rewind a broken one.
- Local and hosted. The same sandbox on a laptop, a server and a cloud.
03How kosa8 meets it
Install kosa8, sign in, then install the Python SDK with the Agents SDK extra.
Create a sandbox with no network and hand its tools to the agent. The tools are named sandbox_shell, sandbox_run_code, sandbox_read_file, sandbox_write_file, sandbox_list_files, sandbox_git and sandbox_preview.
from agents import Agent, Runner from kosa8 import Kosa8Client from kosa8.integrations.openai_agents import sandbox_tools client = Kosa8Client() client.create_sandbox(name="agent-1", egress="deny", ephemeral=True, auto_stop_min=30) agent = Agent( name="coder", instructions="Write code in /workspace and test it with the sandbox tools.", tools=sandbox_tools(client, "agent-1"), ) result = Runner.run_sync(agent, "write fizzbuzz in Python and test it") print(result.final_output) client.delete_sandbox("agent-1")
egress="deny" closes the network, DNS included, on the host side. To let it install packages, pass egress_allow=["pypi.org", "files.pythonhosted.org"] instead. ephemeral=True deletes the sandbox whenever it stops, so a crashed script leaves nothing behind.
If you already use the Agents SDK's own sandbox clients, point DOCKER_HOST at kosa8 and the SDK's Docker client puts its sandbox in a microVM; that guide has the steps.
04When another option fits better
- OpenAI's hosted code interpreter. The Responses API's hosted tools run code on OpenAI's side with no machine for you to manage. Use it when the data may go there and you do not need your own environment.
- The SDK's other sandbox clients. If your team already pays for a hosted sandbox provider the SDK supports, using it avoids a second system.
- Docker alone. For code you trust, a container is enough and starts quickly. It shares the host kernel.
05FAQ
Is there a kosa8 integration for the OpenAI Agents SDK?
Yes. pip install 'kosa8[openai-agents]', then from kosa8.integrations.openai_agents import sandbox_tools. It returns FunctionTool objects bound to one sandbox.
Can several agents share one sandbox?
They can, by passing the same sandbox name to sandbox_tools(), but each agent then sees the others' files. For separate work, give each agent its own sandbox or fork a prepared one with client.fork().
Does it work on Windows?
Yes, through WSL2: once kosa8 wsl setup has run, Kosa8Client() reaches the engine in WSL2 with no configuration.
Can I use the same code with kosa8 Cloud?
sandbox_tools() drives the local daemon or a paired worker. For kosa8 Cloud, use Kosa8Cloud and call box.exec() from your own function tool.
06Get started
Install kosa8 on a Mac, Linux or Windows (WSL2) machine, or make an account and run the same sandboxes on kosa8 Cloud.
07Sources
- kosa8 docs: Agent frameworks (Python)
- kosa8 docs: Python quickstart
- kosa8 docs: RL rollouts and evals (Python)
- OpenAI Agents SDK documentation
- kosa8 command reference
Related
- How do I give the OpenAI Agents SDK a local sandbox?
- How do I run untrusted LLM-generated code safely?
- How do I build a self-hosted code interpreter for my LLM?
- How do I build an RL environment rollout loop on sandboxes?
- All best-sandbox pages
Updated 2026-11-14