Skip to main content
Give an agent in a Temporal workflow an Agent37 sandbox to work in. Temporal’s OpenAI Agents integration runs every sandbox operation (creating it, each command, each file read and write, deleting it) as its own activity, so a worker that crashes part-way through a run picks it up where it stopped, against the same sandbox. The sandbox client is the one file from the OpenAI Agents SDK guide, with no package to install.

Install

Use Python 3.11 or newer, an Agent37 API key, a funded workspace wallet, and a Temporal server. The Temporal CLI runs one locally.
Save agent37_sandbox.py next to the three files below.

Write the workflow

The workflow names a sandbox provider, agent37, and the worker decides what that name means.
coding_workflow.py
Import the options inside imports_passed_through(), because Temporal’s workflow sandbox blocks the HTTP library the client file imports.

Run the worker

Register the Agent37 client under the same name. The worker process is the only place that needs AGENT37_API_KEY and OPENAI_API_KEY.
worker.py

Start a run

start.py
The run creates an instance, and the Temporal Web UI at http://localhost:8233 shows each step as an agent37-sandbox_* activity between the model calls. The instance is deleted when the run ends, including when it fails. Instances bill your workspace while they exist; OpenAI bills model calls separately.

Retries do not run a command twice

Temporal retries an activity whose connection dropped, whose worker died, or that passed its timeout. Inside an activity, the client sends each command under a name taken from the workflow run, the activity, and the command. Agent37 runs a named command once: a retry gets that run’s result, waiting for it if it is still running, and the command does not start a second time. A name is remembered while its command runs and for 5 minutes after it finishes. Sandbox activities get 5 minutes by default, and a command can run for up to 15. Give long commands the time they need:
A call Agent37 refuses (a revoked key, a deleted instance, an empty wallet) fails the activity without retries. A dropped connection or a 5xx is retried.

Sleep while a workflow waits

A workflow can wait hours for a person or a timer. Turn on auto-sleep and the instance sleeps while nothing runs in it, paying for disk alone, and the next command wakes it with its files and running processes as they were:
create_options accepts the JSON fields from Create an instance, such as resources, env, region, and type. The rest of the client (keeping files between runs, attaching to an existing instance, choosing a template) is in the OpenAI Agents SDK guide.