Codex Harness Architecture: State, Compaction, Interfaces, and Security Boundaries
From Codex, two practices carry over to other tools. The first is choosing an integration depth: use codex exec when you only need the final result, an SDK to start and resume agents from code, App Server for an editor or workbench with approval UI, and the hosted Agents API when you do not want to run the harness yourself. The second is testing context compaction as a state transition: the user’s goal, the working directory, permissions, and unfinished steps must all survive it.
OpenAI describes the harness in Codex as a platform as the open-source execution system behind the different Codex clients; the four interfaces below are all built on it.
Four Integration Depths
The further down the table, the more of the lifecycle the application owns itself; with the Agents API, harness operation and session state pass to OpenAI instead.
The Harness Records an Execution Trace, Not Just a Chat
App Server represents runtime state as Thread → Turn → Item. A Thread is a continuing conversation, a Turn is one user request and the agent work that follows, and Items record messages, commands, file changes, and tool calls. Items become context for later Turns, so the harness preserves an execution trace rather than chat text alone.
Compaction Is a State Transition
The compaction implementation does not simply delete old messages. It first has the model write a summary, then replaces the whole history with three things: that summary, the most recent user messages (up to an estimated 20,000 tokens), and reinjected initial context.
Four things must come through compaction unchanged: the user’s goal, the working directory, permissions, and unfinished steps. Lose any one and the agent forgets where it is, what it may do, or repeats a step it already completed. Testing compaction therefore means checking each of these four items, not only how much shorter the history became; the general rules for what a summary must keep are in Context Engineering for Agents.
Sandbox and Approval Are Separate Boundaries
Codex's security documentation configures the sandbox and approvals separately: disabling approvals does not remove the sandbox, and only --dangerously-bypass-approvals-and-sandbox bypasses both. For how these two layers compare with other tools, and the defaults of each mode, see Agent Security.