Run the commands of the OpenAI Agents API in Upstash Box. The agent runs on OpenAI's side, and each session gets its own box where its commands run. Every box includes the Codex CLI, so there is nothing to install.
1. Get your keys#
- A Box API key from the Upstash Console.
- An OpenAI API key from API keys.
- An environment key from Agents → Environments → Keys, in the same project. It's the only OpenAI key that goes into the box.
.env
2. Run a session#
session.ts
The agent's commands run in the box. When the turn is done, the box is paused and keeps its files.
3. Continue later#
Pass the printed IDs to continue the same session in the same box:
resume.ts
When you are done, delete the session, then the box:
Customize the box#
Pass any Box.create option when you create the box:
CODEX_API_KEY is readable inside the box, which is why it must be the environment key. Open a server the agent started with box.getPublicURL(3000). To start every box with your own tools or repo, create it with Box.fromSnapshot instead.
Troubleshooting#
- Script waits and prints nothing: the executor didn't connect. Check
/workspace/home/executor.login the box. missing required scope api.agents.environments.connect:OPENAI_EXECUTOR_KEYmust be an environment key, not a regular API key.