Skip to main content

Module codex

Module codex 

Source
Expand description

Codex agent runner.

§CLI invocation

codex --model {model} \
  exec \
  -c 'sandbox_workspace_write.network_access=true' \
  -c 'shell_environment_policy.inherit=all' \
  --sandbox workspace-write \
  -c 'approval_policy="never"' \
  --json - < <(cat "{sys_file}" "{msg_file}")

Note: all -c overrides must appear after the exec subcommand. Global -c flags before exec are parsed by the top-level codex CLI and do NOT propagate into the exec subcommand’s sandbox — placing sandbox_workspace_write.network_access=true before exec silently fails, leaving the sandbox network-blocked.

§Output format (exec --json)

NDJSON stream (one JSON object per line):

{"type":"thread.started","thread_id":"..."}
{"type":"turn.started"}
{"type":"item.completed","item":{"type":"agent_message","text":"..."}}
{"type":"item.completed","item":{"type":"command_execution","command":"..."}}
{"type":"turn.completed"}

§Error events

Rate limit:

{"type":"error","message":"You've hit your usage limit..."}
{"type":"turn.failed","error":{"message":"..."}}

Model not found:

{"type":"item.completed","item":{"type":"error","message":"Model metadata for `o3-mini` not found..."}}
{"type":"error","message":"{\"detail\":\"The 'o3-mini' model is not supported...\"}"}
{"type":"turn.failed","error":{"message":"..."}}

Structs§

CodexRunner
Runner for Codex agent.

Functions§

find_codex_result
Extract a structured AgentResult from Codex NDJSON output.