Skip to main content
Give a SandboxAgent from the open-source OpenAI Agents SDK an Agent37 sandbox to work in. Your application runs the agent loop and calls the model. Agent37 runs the agent’s commands and stores its files. The client is one Python file with no package to install. It works with the default agent37-base template, so you do not need an agent harness inside the instance. For OpenAI’s hosted Agents API, see OpenAI Agents API on Agent37 instead.

Install

Use Python 3.10 or newer, an Agent37 API key, and a funded workspace wallet. The examples use your own OpenAI key for the model.
Save this file as agent37_sandbox.py next to your code. It is tested with openai-agents 0.22 and 0.24.
agent37_sandbox.py

Run an agent

The runner creates an instance for the run and deletes it when the run ends, including when the run fails. Instances bill your workspace while they exist; OpenAI bills model calls separately. The agent gets the SDK’s default tools: shell commands, file edits with apply_patch, and image viewing. Commands run as root in /workspace. Each command starts a fresh shell, so files persist between commands but shell variables and cd do not. A command can run for up to 15 minutes, and one that passes the timeout the agent sets is stopped.

Keep files between runs

Create a sandbox yourself and pass it to each run to share one workspace:
Leaving the async with block deletes the instance. To come back to the same files from another process, store sandbox.state.instance_id and attach to it later:
The client never deletes an instance it attached to. Delete it with Delete an instance when you are done. Attached instances must be running or sleeping; a command wakes a sleeping one.

Choose a template and resources

create_options accepts the JSON fields from Create an instance, such as resources, env, region, and auto_sleep. With auto_sleep, an instance you keep between runs sleeps while idle and pays for disk alone. Custom templates need a POSIX shell, tar, and GNU coreutils. The client does not support PTY sessions, exposed ports, or storage mounts.

Run on Temporal

Temporal’s OpenAI Agents integration runs each sandbox operation as its own activity. Install it with pip install temporalio-openai-agents, then register the client on the worker:
The worker process needs AGENT37_API_KEY and OPENAI_API_KEY. In the workflow, name the same provider:
Import the options inside imports_passed_through(), because Temporal’s workflow sandbox blocks the HTTP library the client file imports.