Speaker Notes

How Codex Works — Dominik Kundel, OpenAI

Codex utilizes an open-source Rust harness and responses API, employing context management, persistent WebSockets, and automated safety reviews to build efficient AI coding agents.

AI Engineer · 20:55 · YouTube ↗

Talk · solo speaker  Advanced · architecture, concepts and code

Highlights

3 clips · 4 min of 21 min
    • Marking tools as deferred keeps them out of the initial context window.
    • Deferred tools are discovered dynamically via tool search.
    • Available skills are capped at 2% of the max context window to prevent bloat.
    • Auto-review uses a separate, read-only sub-agent to judge potentially risky actions.
    • The sub-agent evaluates user authorization and risk taxonomies against the transcript.
    • This approach removes user approval fatigue while maintaining data exfiltration protections.
    • Fast inference models expose network latency as the new performance bottleneck.
    • Persistent WebSockets replace HTTP and server-sent events to save network overhead.
    • Stateful WebSockets send only the data that changed, drastically improving interaction speed.

Questions this video answers

9 · every answer cites the moment it was said
01 How do protocols manage communication in the Codex ecosystem? 2 sources · 2:00

The Codex ecosystem uses two main protocols to handle communication. The app server protocol connects the UI to the harness, while the responses API manages communication between the harness and LLM inference. Both are open and allow developers to build custom UIs or integrate with compatible model providers.

02 How does Codex manage context size and cost during construction? 2 sources · 4:29

Codex optimizes context size to control token budgets and reduce model confusion from contradictory information. It achieves this by using deferred tools that load via tool search and by capping available skills at two percent of the total context window. These strategies ensure performance and cost-efficiency while supporting numerous plugins.

03 How does the agent execute asynchronous tasks like sub-agents? 2 sources · 7:18

Codex delegates tasks asynchronously by providing the agent with a spawn agent tool to create new instances. It uses a send input tool to communicate with these sub-agents or background terminals and wait for them to finish. This design allows the main agent to continue working while background processes run.

04 How does Codex handle browser interaction and computer use? 2 sources · 8:42

Rather than step-by-step restricted computer use actions, modern Codex models use code execution for flexibility. Browser tasks interact with a persistent node REPL running JavaScript and Playwright. This enables the agent to script interactions, inspect pages, and perform efficient scraping across turns.

05 How does Codex interact with the file system and local tools? 2 sources · 10:15

Models starting with GPT-5 are trained to use an apply patch tool for editing files via diffs and creating new ones. For navigation and searching, the harness relies on a shell tool and ships with Ripgrep or PowerShell depending on the OS. All file interactions pass through OS-specific sandbox layers like Seatbelt, Bubblewrap, or a custom Windows sandbox.

06 How does auto-review prevent approval fatigue and security risks? 2 sources · 13:13

To avoid constant manual approvals without granting full unrestricted access, Codex uses an auto-review sub-agent. When a high-agency action triggers a sandbox escalation, this read-only sub-agent evaluates the transcript, risk taxonomies, and user authorization context. It automatically approves safe actions while blocking dangerous ones like data exfiltration.

07 When should I use WebSockets instead of server-sent events for inference? 2 sources · 15:55

WebSockets should be used when high-speed token generation makes network overhead the primary bottleneck rather than inference. A persistent WebSocket connection saves network overhead and maintains stateful context. This allows the system to send only updated items, such as tool call results, instead of transmitting the entire payload repeatedly.

08 How do agent loops manage task goals and continuation? 2 sources · 18:10

Agent loops automatically inject a continuation prompt containing the original objective when tasks run over multiple steps. The harness continues this loop until the model explicitly calls a tool to update the plan and signal that the goal is achieved. Developers should write clear, verifiable prompts rather than long essays to make goal detection reliable.

09 How does auto-compaction handle long-running agent sessions? 2 sources · 18:53

For sessions running over hours or days, Codex uses auto-compaction to prevent context overflow. This feature can be triggered manually or automatically on the server side to compress previous context windows. It turns the transcript into a new context containing a compaction item with all necessary ongoing information.

Section-by-section summary

4 parts

Dual protocols power the open Codex ecosystem

The app server handles communication between the user interface and the harness, while the responses API manages inference with built-in capabilities like web search. Both protocols are open source, allowing developers to plug Codex into various platforms or build custom interfaces.

Context construction balances size and cost

Context building manages token budgets by capping available skills at two percent of the total window and using deferred loading for tools. Deferred tools are only loaded via tool search to prevent context bloat and contradictory information.

Advanced actions combine sub-agents and computer use

The agent performs async actions using sub-agents and background terminals, while browser interactions script Playwright code inside a persistent node REPL. File system modifications rely on native diff patches and shell tools wrapped in OS-specific sandboxes.

Auto-review and websockets optimize agent execution

An autonomous review sub-agent automatically approves safe actions to eliminate approval fatigue without compromising security. Additionally, persistent WebSocket connections and server-side compaction drastically reduce network overhead and maintain stateful context over long tasks.

0:00 / 20:55
k play/pause · f fullscreen · m mute
n next · p previous clip · t highlights/full
< > slower/faster · / search what was said
  • Codex harness11× · first 0:34

    The open-source core framework written in Rust that manages the Codex coding agent.

  • App server protocol4× · first 2:11

    The protocol handling communication between the user interface and the Codex harness.

  • Responses API7× · first 2:18

    An open API standard managing communication between the harness and LLM inference.

  • Tool search3× · first 6:13

    A capability to defer loading tools into context until discovered via search.

  • Apply patch tool1× · first 10:21

    A tool used by models to edit files using diffs and create new files.

  • Auto review3× · first 13:15

    A security sub-agent that evaluates high-agency agent actions and automatically approves safe operations.

  • Auto compaction1× · first 19:03

    A server-side feature that condenses long transcripts into a compact context window.