Somewhere in your repo there's a 400 line agent loop that compacts context and babysits a container, and it's the file nobody wants to open. On 10 September OpenAI put that loop behind an API. The Agents API is the Codex harness sold as a managed service, in public beta for every developer, with no fee of its own. You pay for tokens and tool calls, plus sandbox minutes if OpenAI hosts the box. We spent a morning in the docs rather than the launch post, and that's where the interesting parts are.
The short answer
Since 10 September 2026, one call to POST /v1/agents/sessions with the OpenAI-Beta: agents=v1 header gives you a Codex-style agent that OpenAI runs for you: context compaction, tool search, subagents, resume. The sandbox can be OpenAI hosted, your own machine running codex exec-server, or one of nine partners. There's no separate API fee. Hosted sandboxes bill at container rates from $0.03 per 20 minutes for 1 GB, and an idle one is deleted after an hour. Data residency is US only, and Zero Data Retention isn't supported, self-hosted sandbox or not.
What one session create actually buys you
Four nouns. An agent is the model, instructions, tools and MCP servers. An environment is the optional sandbox where it reads files and runs commands. A session is a durable instance of that agent, and events and items are what goes in and what comes out. You create a session with the agent config and an input, then stream events or wait on a webhook. Send another input to the same session and the agent picks up where it stopped, with OpenAI holding the state.
The harness is the part we'd have paid for. It compacts earlier context automatically as a session nears its limit, so a job can span several context windows without you writing the summariser. Tool search loads tool definitions on demand instead of stuffing them all into the prompt, and programmatic tool calling lets the model filter results in code before they touch the context. Subagents are a flag: multi_agent.enabled with max_concurrent_subagents, which defaults to 6, not counting the coordinator. Honestly, that default feels high to us for anything billed per token, and we'd set it to 2 or 3 until we'd seen a bill.
The default model in every example is gpt-6-astra. The harness is the open source Codex one, so you can read the coordination logic even though OpenAI runs it. Your key needs api.agents.read, api.agents.write and api.responses.write, and it stays out of the sandbox. The docs repeat that three times. They're right to.
Three places the sandbox can live, and what each one costs
Option one is openai_hosted. You get a Linux workspace at /workspace with Python and Node.js, pinned packages if you list them, setup commands that run before the agent starts, and input files inline as base64 or by Files API ID. Network access has three modes: enabled (the default), disabled, or restricted to a list of 1 to 100 exact hostnames, no wildcards, no ports, and every subdomain and redirect target needs its own entry. Anything written under /workspace/outputs becomes an immutable artifact when the turn completes, and those copies survive the sandbox. The sandbox itself doesn't. An hour without activity or keep-alives and it can be deleted, and you can't change that timeout.
The price for that hosted box is the standard container rate on the pricing page: $0.03 per 20 minute session for 1 GB, $0.12 for 4 GB, $0.48 for 16 GB and $1.92 for 64 GB, with eligible sessions billed by the minute and a 5 minute minimum. Cheap, until you remember the keep-alives run between turns too, so a session you forgot to delete is a sandbox you're paying for. We'd put the delete in a finally block.
Option two is self_hosted, and it's the one we like. OpenAI still runs the harness, but the executor is a process you start inside an environment you trust, a laptop or a container:
npm install -g @openai/codex@alpha Then codex exec-server registers with the API using the session's environment ID and a restricted key you create on the Agents tab with every other permission set to None, supplied as CODEX_API_KEY. All connections are outbound, to two hosts: HTTPS to api.openai.com for registration, then a WebSocket to codex-cloud-environments.chatgpt.com for commands and results. That's the whole firewall conversation, which is more than we can say for most agent products. Two caveats from the lifecycle page. The API waits up to five minutes for the executor to connect when input arrives, then fails the submission. And deleting a session neither stops your compute nor sends a webhook, so cleanup is yours. Option three is a partner sandbox: Modal, Cloudflare, Vercel, Daytona, Blaxel, E2B, Runloop, DigitalOcean and Oracle Cloud each have a setup guide, and they're all option two with someone else's provisioning.
The fine print for anyone outside the US
Two lines in the overview undo a lot of enterprise conversations. The Agents API currently supports data residency only in the United States, and it does not support Zero Data Retention. Running the sandbox on your own hardware doesn't change that; the docs say a self-hosted sandbox does not make the API ZDR-eligible, since the session state and artifacts live with OpenAI wherever the commands execute. If you built a compliance story on Private Safety Processing keeping ZDR alive, it stops at this endpoint for now. Beta, so this may move. Today it hasn't.
The token side is the bigger bill. GPT-6 Astra lists at $10 in and $50 out per million tokens on short context, and $20 and $75 once you cross into long context. A harness that keeps an agent working for hours pushes you toward that cliff, and compaction is supposed to pull you back from it. Whether a compacted session actually stays on the short context rate isn't spelled out anywhere we could find, and there's no worked bill in the docs. I might be wrong about how much that matters, but we'd run the first week on gpt-5.6-terra at $2 and $12 and read the usage page before switching. The customer numbers in the launch post, a 4x latency drop, 60 percent lower cost per case, 86 percent fewer failed responses, all come from the customers themselves. Nobody outside those companies has re-run them.
Sources
OpenAI, Introducing the Agents API, 10 September 2026 (the public beta, the harness features, the partner list, the no-fee statement and the customer quotes). OpenAI developer docs, Agents API overview, OpenAI-hosted sandboxes, Self-hosted sandboxes and Pricing, read 14 September 2026 (the four concepts, the residency and ZDR note, the network modes, the one hour expiry, the executor hosts, the subagent default and the container rates). MarkTechPost, OpenAI launches the Agents API in public beta, 10 September 2026 (independent read of the launch, including the residency and ZDR limits).
Frequently asked questions
Is the OpenAI Agents API free?
The API itself carries no fee. You're billed for the model tokens each session uses at that model's API rate, for OpenAI tools such as web search at their standard rates, and for hosted sandbox time at container rates, from $0.03 per 20 minute session for a 1 GB container up to $1.92 for 64 GB. A self-hosted or partner sandbox moves the compute bill to you or the partner instead.
Can I run the Agents API sandbox on my own servers?
Yes. Set the environment type to self_hosted, install the Codex CLI in your environment and run codex exec-server with a restricted environment key. The executor makes outbound connections only, to api.openai.com and codex-cloud-environments.chatgpt.com. OpenAI still runs the harness and stores the session state; only the commands and files live on your side.
Does the Agents API support Zero Data Retention or EU data residency?
Not in the public beta. The overview states that data residency is supported only in the United States and that Zero Data Retention isn't supported, and it says explicitly that a self-hosted sandbox doesn't make the API ZDR-eligible. If either is a hard requirement, you're still on the Responses API for now.
How long does an OpenAI-hosted sandbox last?
While it's connected it receives keep-alives, including between turns. Once activity and keep-alives stop for an hour the sandbox can be deleted, and that timeout isn't configurable. Files under /workspace/outputs are published as immutable artifacts at the end of each turn and stay downloadable after the sandbox is gone; anything else in the workspace goes with it.






















