Skip to content

Codex automation: pick the surface, then prove the result

Codex automation means running Codex with nobody at the prompt: codex exec in scripts and CI, scheduled automations in the Codex desktop app, Codex cloud tasks, parallel worktrees, the Codex SDK, and delegation from Slack or Linear. A run is only as trustworthy as the machine check that decides whether its output merges.

You already use Codex interactively and have chores it could do alone: the nightly flaky-test sweep, dependency bumps, triage of failed CI runs. This hub is for developers and tech leads deciding which surface runs each one, and how to know the result is right without reading every diff. It was checked against Codex CLI 0.157.1.

Choose by trigger and by what the run must reach. A job that needs your local services belongs on your machine. A job that must run while your laptop sleeps belongs in CI or on Codex cloud.

Your jobSurfaceTriggerRead
Scripted or CI step with a machine-readable resultcodex exec (--json, --output-schema, -o)Your script or pipelineHeadless Codex with codex exec
Recurring check or reportDesktop app automations (macOS and Windows; runs only while that machine is awake), or a CI scheduleClockScheduled Codex automations
Long or remote task, several attemptsCodex cloud (codex cloud exec --env ENV_ID --attempts 3; experimental in CLI 0.157.1; codex cloud lists environment IDs, --attempts is best-of-N)CLI, web or integrationCodex cloud environments
Several local tasks at onceManaged worktrees (--worktree, /worktree)YouCodex worktrees and multi-agent workflows
Your own tool or dashboard drives Codex@openai/codex-sdk (TypeScript) or openai-codex (Python)Your codeCodex SDK
A request starts in chat or a ticketSlack and Linear integrationsA mention or assignmentSlack and Linear
Pull request review and fixes in GitHubopenai/codex-action@v1Workflow eventCodex in CI/CD
Gateways, sandbox tests, audit trailsConfig and telemetrySetupAdvanced Codex setups

The same jobs in Claude Code and Cursor live in the Claude Code automation hub and the Cursor automation hub. To choose between vendors’ SDKs, read driving agents from code.

Each step reuses what the previous one proved. Skipping ahead means debugging the prompt, the sandbox and the schedule at the same time.

  1. Run the task interactively until it succeeds twice and write down the command that proves it, such as pnpm test or pnpm lint. That command becomes the run’s gate.

  2. Run it headless with the narrowest permissions and a fixed output shape. In a terminal:

    Terminal window
    gh run view "$RUN_ID" --log-failed | codex exec -c default_permissions=":workspace" \
    --output-schema triage.schema.json -o triage.json \
    "Triage the failing tests in the CI log on stdin. Do not edit test files."

    RUN_ID is the ID of the failed GitHub Actions run (gh run list --status failure prints it). When a prompt argument is given, codex exec appends piped stdin to it as a <stdin> block.

    triage.schema.json fixes the shape of the final message:

    {
    "type": "object",
    "additionalProperties": false,
    "required": ["failing_tests", "suspected_cause", "flaky", "confidence"],
    "properties": {
    "failing_tests": { "type": "array", "items": { "type": "string" } },
    "suspected_cause": { "type": "string" },
    "flaky": { "type": "boolean" },
    "confidence": { "type": "string", "enum": ["low", "medium", "high"] }
    }
    }

    Permission profiles are beta (CLI 0.138.0 and later) and do not compose with the legacy --sandbox flag: in 0.157.1, passing both starts without an error and --sandbox silently replaces the profile. Pass one or the other, and check the sandbox: line in the run header. --approve-for-me runs on the legacy workspace-write sandbox, so it does not compose with a profile either. Pick one control. --full-auto no longer exists (removed in 0.147.0). The permissions and sandboxing guide sets the posture per run type.

  3. Parallelise once one run is reliable: one worktree per task.

  4. Schedule it or move it to the cloud.

  5. Wire it into CI so the pipeline, not the agent’s own report, decides the result.

  6. Reach for the SDK last, when a script around codex exec can no longer express the flow.

How do you verify unattended Codex output without reading every line?

Section titled “How do you verify unattended Codex output without reading every line?”

Trust the gates, not the agent’s summary. A working setup has four layers:

  • A fixed output shape. --output-schema describes the final message; your script still checks that the field is present and the model is not unsure (jq -e 'has("failing_tests") and .confidence != "low"' triage.json) before acting on it.
  • Independent checks. CI reruns the tests, type check and lint on the branch Codex pushed. The agent cannot mark its own work green.
  • A second reviewer. codex exec review --base main or @codex review on the pull request looks for bugs the tests miss. See Codex code review.
  • An audit trail. --json writes every event as JSONL; archive it with the run so you can answer “what did it do?” later.

A human still signs off at the merge, on the evidence: green gates, the review findings and the contract’s report. The evidence bundle page defines what that package contains.

SymptomCauseRecovery
unexpected argument '-a'codex exec has no -a in 0.157.1, and does not need one: without --approve-for-me it runs with approval never, whatever approval_policy or a codex -a … exec prefix says. With --approve-for-me the header shows on-request and auto-review decidesDrop the flag and check the approval: line in the run header: never normally, on-request under --approve-for-me. Limit what the run can do with the sandbox or permission profile instead
The run has wider or narrower access than the profile--sandbox passed alongside default_permissions; the flag silently wins in 0.157.1Drop one of them and confirm the sandbox: line in the run header
Script fails on --full-autoFlag removed in 0.147.0Use a permission profile, as in step 2
The run ignores project rulesUntrusted projects do not supply AGENTS.md (since 0.150.0)On the runner, add [projects."REPO_PATH"] with trust_level = "trusted" to $CODEX_HOME/config.toml (REPO_PATH is the absolute checkout path on the runner) (configuration). Trust only a checkout of your own default branch: a trusted contributor head supplies its own AGENTS.md, project config and hooks
Project hooks do not fireHooks need persisted trustApprove them once with /hooks; avoid --dangerously-bypass-hook-trust
Parallel runs break each otherShared ports, database or branchOne worktree and one port block per run
A secret leaks from a PR-triggered jobUntrusted code ran with secrets in the environmentFollow agent identity and secrets before enabling the trigger

Never pass --dangerously-bypass-approvals-and-sandbox outside a disposable, network-restricted sandbox.