Codex CLI security for teams

Codex CLI security rests on three settings working together: the sandbox mode (what the agent can touch), the approval policy (when it must ask) and hooks (a script or service that checks each tool call before it runs). For a team, pin all three centrally in requirements.toml so a developer's local config cannot loosen them, block the bypass flags, and record every decision in an audit log.

Last updated: · Checked against learn.chatgpt.com/docs on 22 November 2026

Works with Claude Code · Cursor · Codex

Contents

The three layers: sandbox, approvals, hooks

  • Sandbox mode limits what commands can reach: read-only, workspace-write or danger-full-access. The "Auto" preset is workspace-write with approvals on-request.
  • Approval policy decides when Codex stops and asks: on-request, never, or a granular table. untrusted is marked retired in the current docs and can stop Codex from starting, so remove it from old configs. approvals_reviewer can be user or auto_review; under auto_review a model, not a person, may answer the request.
  • Hooks run your own check. A PreToolUse hook sees Bash, apply_patch, MCP and local function calls before they run, and denies with permissionDecision: "deny" (or exit code 2). It does not support "ask".

Pin the settings centrally with requirements.toml

Codex reads managed requirements that users cannot override. Use them to set allowed_approval_policies and allowed_approvals_reviewers, enforce hooks = true, and set allow_managed_hooks_only = true so project and user hooks cannot replace yours. On Windows the managed files live under %ProgramData%\OpenAI\Codex\; on Linux and macOS under /etc/codex/. Hooks are on by default unless [features] hooks = false, so a policy that forces hooks = true closes that switch.

The bypass flags to block

  • --dangerously-bypass-approvals-and-sandbox (alias --yolo) turns off approvals and the sandbox together. It belongs in throwaway containers, never in CI with secrets or on a developer laptop with production credentials.
  • --dangerously-bypass-hook-trust skips the review step for non-managed hooks.
  • CODEX_HOME points Codex at a different config folder, and with it different hooks.

A hook that checks shell commands should deny commands that start Codex with these flags or change these files, so the agent cannot switch its own guard off.

Check every file in a patch, not the first one

Codex edits files through apply_patch, and one patch can add, update, delete and move several files. A path rule (for example "never write to .github/workflows/") has to read every *** Add File:, *** Update File:, *** Delete File: and *** Move to: line in the patch. Checking the first path lets a second file through.

Fail mode: what happens when the check cannot answer

Decide per tool class. For shell, file changes and MCP calls, deny when the policy service does not answer in time; for reads, allowing is often acceptable. Keep the hook's own deadline well under Codex's hook timeout so the decision is yours, not a timeout's.

How SecGuardRail connects to Codex CLI (beta, Windows)

  • The Windows install script places a small forwarder in C:\ProgramData\SecGuardRail\codex (writable by administrators, readable by users) and merges a marked block into %ProgramData%\OpenAI\Codex\requirements.toml. It refuses unsafe merges (existing hooks, hooks = false) with no change and ends with a live canary command that must be denied and recorded; if the canary fails, everything is put back.
  • Each Codex tool call goes through the same policy, approvals and audit log as Claude Code and Cursor. apply_patch is checked on every path in the patch; MCP calls are recorded with server and tool.
  • The forwarder has a 5 second deadline. If our service is unreachable, slow, returns an error or the key is revoked, it applies the workspace fail mode per tool class; a missing fail-mode file means closed.
  • Three always-on Tamper Protection policies cover ~/.codex, .codex/, requirements.toml, managed_config.toml, the Codex managed folder, --dangerously-bypass-hook-trust, CODEX_HOME and features.hooks.
  • Risky actions can be held for a person: the Slack alert links to the request, and an approver decides in the dashboard.

Honest limits

  • If the hook process itself is killed, Codex runs the action (openai/codex#41979).
  • A local administrator can edit requirements.toml; tamper policies catch the agent doing it, not an admin.
  • PreToolUse does not cover hosted tools such as web search. OpenAI's own docs call hooks a useful guardrail, not a complete enforcement boundary; keep the sandbox on.
  • Our Codex connector is Windows today (beta).

What changed in Codex security recently (checked 2 Dec 2026)

Fail-closed hooks in Codex 0.173.0 (December 2026)

Codex CLI 0.173.0 (2 December 2026) lets supported synchronous command and MCP tool hooks set onFailure to block. If a PreToolUse check fails, the tool does not run. Running threads also pick up changed approval requirements when you reload the configuration.

SecGuardRail's Codex installer does not set onFailure yet. Its forwarder answers by the workspace fail mode when it cannot reach our service (see the limits above).

Codex 0.172.0 and earlier (November 2026)

  • Codex CLI 0.172.0 (24 November 2026) adds an approval reviewer per app tool and restores sandbox permissions when you resume with codex exec resume.
  • Linux sandbox: seccomp restricts x32 syscalls and request_key is blocked in the network sandbox.
  • Docs moved to learn.chatgpt.com; approval policy untrusted is retired.

Codex CLI security checklist

  1. requirements.toml pins approval policies and reviewers.
  2. hooks = true enforced, allow_managed_hooks_only = true.
  3. No --yolo / --dangerously-bypass-approvals-and-sandbox outside disposable containers.
  4. A PreToolUse hook on Bash, apply_patch and MCP, checking every patch path.
  5. Fail closed on shell, writes and MCP.
  6. Deny agent edits to .codex/, requirements.toml and CODEX_HOME.
  7. Every decision in an audit log you can export.

FAQ

Can a Codex hook ask the user instead of blocking?

No. A PreToolUse hook in Codex can allow or deny; "ask" is not supported. Use the approval policy for prompts, or a service that holds the action for a named approver.

What does --yolo do in Codex?

It is the alias of --dangerously-bypass-approvals-and-sandbox: no approvals and no sandbox. Use it in disposable containers, not on machines with real credentials.

Can a developer turn the hooks off?

Not if requirements.toml enforces hooks = true and allow_managed_hooks_only = true; a local administrator still can, which is why agent edits to those files should be denied and logged.

Does the same policy work for Claude Code and Cursor?

Yes. SecGuardRail applies one policy, one approval queue and one audit log to Claude Code, Cursor and Codex. See Claude Code security for teams.

Set it up

Become a design partner

Design partners: Team plan free for 30 days, then 50% off for life, limited to 10 teams. We set it up with you on a 20-minute call.

Agents you use

0/1000

We store this to contact you. See Privacy.

Plans

  • Free

    $0

    • 1 developer, 1 workspace
    • 3 agent API keys
    • 10,000 agent events a month
  • Starter

    $50/mo

    • Up to 3 developers
    • Everything in Free
    • Approvals with timeout
  • Team

    $99/mo

    • Up to 10 developers
    • +$9 per extra developer
    • Everything in Starter
  • Business

    From $499/mo

    • Everything in Team
    • Agent discovery
    • Retention and legal hold
See full pricing

Compare hooks, sandboxes and gateways across Claude Code, Cursor and Codex. Connect Codex CLI in the docs. Related guides: Claude Code security for teams and Cursor hooks security for teams, and MCP security for coding agents. See pricing, or join as a design partner.

Sources

Guardrails for Claude Code, Cursor and Codex

Request access