Contents
The three layers: sandbox, approvals, hooks
- Sandbox mode limits what commands can reach:
read-only,workspace-writeordanger-full-access. The "Auto" preset isworkspace-writewith approvalson-request. - Approval policy decides when Codex stops and asks:
on-request,never, or a granular table.untrustedis marked retired in the current docs and can stop Codex from starting, so remove it from old configs.approvals_reviewercan beuserorauto_review; underauto_reviewa 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 withpermissionDecision: "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-trustskips the review step for non-managed hooks.CODEX_HOMEpoints 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_patchis 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_HOMEandfeatures.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_keyis blocked in the network sandbox. - Docs moved to learn.chatgpt.com; approval policy
untrustedis retired.
Codex CLI security checklist
requirements.tomlpins approval policies and reviewers.hooks = trueenforced,allow_managed_hooks_only = true.- No
--yolo/--dangerously-bypass-approvals-and-sandboxoutside disposable containers. - A PreToolUse hook on Bash,
apply_patchand MCP, checking every patch path. - Fail closed on shell, writes and MCP.
- Deny agent edits to
.codex/,requirements.tomlandCODEX_HOME. - 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.