Skip to slide
005 / 170

CH 01 · What Is an Agent Harness? · 05/12

Read as one page

Real code: Codex splits the harness into crates

The six-layer table in "How it works: two mental maps" names the jobs around the model: input, knowledge, execution, integration, multi-agent, and observability. Codex, OpenAI's coding agent, puts each job in its own Rust crate, one library or program. codex-rs/Cargo.toml, at this commit, lists 157 of them. The request that reaches the model is codex-api, one dependency of core. Most of the other names are harness: permissions, hooks, sandboxing, memory, session files, telemetry, and tools.

    "skills",
    "core", # [1]
    "core-api",
    "core-plugin-common",
    "core-plugins",
    "diagnostics",
    "guardian-context",
    "hooks", # [2]
    "history",
    "http-client",
    "secrets",
    "exec",
    "file-system",
    "exec-server-protocol",
    "exec-server",
    "exec-server/tests/support",
    "execpolicy", # [3]
    "ext/agent",

Source: openai/codex, codex-rs/Cargo.toml (Apache-2.0)

    "linux-sandbox", # [4]
    "lmstudio",
    "login",
    "codex-mcp",
    "memories/read",
    "memories/write",
    # ... (5 lines)
    "ollama",
    # ... (6 lines: process hardening, voice, the protocol crate, prompts)
    "rollout",
    "rollout-trace",
    # ... (3 lines)
    "sandboxing",
    # ... (1 line)
    "otel",
    # ... (4 lines: a trace websocket, the TCP tunnel, the terminal UI, user verification)
    "tools",

Source: openai/codex, codex-rs/Cargo.toml (Apache-2.0)

What to notice

  1. [1] core is the business logic the Codex UIs call, which its readme says in the first paragraph. In the six-layer table, this is the execution layer, the loop. The model call is the separate codex-api client.
  2. [2] hooks runs your code at named moments, including before a tool runs. The Harness class later in this chapter has no such pause: the model asks, and that class runs the tool. history holds the types for model history and for persisted rollout records. rollout stores the session files.
  3. [3] execpolicy is the permission check that class stores in permissions. A rule matches the start of a command, written in Starlark, a small configuration language, and the decision is allow, prompt, or forbidden. That is the input layer. skills loads skill folders, and it notices when a command reads a skill document or runs a skill script.
  4. [4] linux-sandbox confines a command on Linux. Its readme says bubblewrap for filesystem and namespace isolation, and seccomp to filter system calls. sandboxing is the shared policy for Linux, macOS, and Windows. memories/read injects saved notes into the prompt. otel exports logs, traces, and metrics. tools builds the tools the model may call.

Read it yourself: Open codex-rs/core/Cargo.toml and find codex-api, codex-execpolicy, and codex-hooks. Then read the three decision values in codex-rs/execpolicy/README.md.

Finished this idea?

Your learning progress stays in this browser.