Skip to main content

OpenAI Agents API

1 min read

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#

.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.log in the box.
  • missing required scope api.agents.environments.connect: OPENAI_EXECUTOR_KEY must be an environment key, not a regular API key.