Skip to content
Agentic Control Plane

Codex Exec and MCP Approvals: Run Headless Without the Bypass Flag

David Crowe David Crowe · · Updated · 8 min read
codex openai cli headless ci mcp approvals
Share X HN LinkedIn

Last updated: November 8, 2026.

Run codex exec in CI or on a schedule and sooner or later an MCP tool call fails with no clear reason. The cause is an open Codex issue, #24135. In non-interactive mode stdin is closed. The tool call needs an approval, nobody is attached to give one, and the call is cancelled.

The reporter says the only way to allow MCP calls without a human is --dangerously-bypass-approvals-and-sandbox, and that this is “not a viable production posture for a daemon.” He’s right. That flag removes the approval gate and the sandbox together. You couldn’t answer one question, so you turned off the gate for every question.

Why this keeps happening

An approval prompt is a question for whoever is watching. A headless run has nobody watching. Every agent that goes headless picks a default. Codex cancels the call, which is the safest of the options. Qwen Code, pi and Prime Agent turn an unanswerable ask into a deny. People try to configure their way out, and the Codex tracker has users guessing at keys like trusted_mcp_servers and mcp_approval_policy. Those keys don’t exist, because the missing piece isn’t a setting. It’s someone to answer.

So don’t ask how to get the prompt approved in CI. Ask why an unattended run is asking questions at all.

A prompt exists because the rules are incomplete. The system doesn’t know if a call is fine, so it asks. That’s cheap when you’re at the keyboard. In a headless run it’s a failure. The fix is to finish the rules before the run starts, so every call the agent might make resolves to allow or deny. A call you didn’t plan for should end in a deny with a reason. The model sees the reason and can work around it. A cancelled run or a bypassed gate teaches it nothing.

The setup that works today

The ACP Approvals page, Approved tab, in our own workspace: 31 approved, 1 rejected, 50 expired. Each card names the tool (Bash.rm), the tier (subagent, unsupervised), the risk tags, the rule that held it, and who answered. One was decided from the approval email's one-tap link.

Approvals raised by unattended runs in our own workspace. 50 of 82 expired before anyone answered, and an expired request counts as denied.

For codex exec in CI or on a schedule:

1. Pin the sandbox. The default is read-only. Use --sandbox workspace-write for jobs that edit files. Use danger-full-access only inside a container you could lose. (--full-auto is deprecated; see the hooks reference.)

2. Keep a PreToolUse hook on the path. Codex keeps PreToolUse firing in sandboxed non-interactive modes. A hook can deny any call it sees, and on current builds that includes shell commands, apply_patch edits and MCP calls. The reason goes back to the model as a tool error. This works with stdin closed. Hosted tools such as web search never reach a hook.

3. Decide ahead of time what you would have approved. This replaces the prompt. The read-only MCP tools, the fetch against your own API and the git push to the PR branch become allow rules. The calls you’d refuse become denies. In a local install you can set "default": "deny" in ~/.acp/policy.json so anything unlisted is denied and logged. In a connected workspace, set the background tier to Never for the dangerous keys. Your own interactive history is a good source for these rules, because the approvals you already gave are the policy you haven’t written down. Codex has a version of this called approved_with_amendment, which saves a one-off approval as a standing prefix rule.

4. Turn enforcement on and decide what happens if ACP is down. A new ACP workspace starts in audit mode: it records every call, and only the safety floor can hold one. Your rules don’t block until you run /acp-enforce or switch it on at the Policies page. The shared hook that Codex uses also fails open if the gateway can’t be reached, in every tier. For CI, set ACP_FAIL_MODE=closed (or echo closed > ~/.acp/failmode) on the runner so an outage stops the run.

5. Keep a record the agent didn’t write. A cancelled MCP call and a policy deny look the same in a green CI log. Whatever enforces your rules should also log every call: what was tried, what was decided, and why.

The safety floor helps here too. With nobody watching, a force-push, destructive SQL sent to a database client, curl | sh or a delete outside the project is held for approval. The request goes to the Approvals page and the owner’s email. If nobody answers, it expires and counts as denied. Deletes of your home directory or system folders are blocked outright.

Steps 2 to 5 are what our Codex integration sets up: the hook, rules checked on every call, and the log. That’s our product, so weigh the advice with that in mind. The pattern works without it: pinned sandbox, a hook, rules decided in advance, loud denies, a record.

What this doesn’t do

It isn’t a mid-run approval. With ACP, a held call is blocked in Codex. You approve it on the console or from the email, and the agent has to retry the call. The run doesn’t pause and resume on its own. Codex can’t show a hook ask as a prompt, so ACP never sends one. Nothing in the Codex ecosystem pauses a call, waits for a person on Slack, and then carries on, and #24135 is open because that plumbing doesn’t exist. Rules decided in advance cover most of what unattended runs need. The rest is small, and the issue is worth watching.

Frequently asked questions

Why do MCP tool calls fail in codex exec?

They are waiting for an approval no one can give. In non-interactive mode stdin is closed, so a tool call that would prompt in an interactive session is cancelled instead. This is tracked in openai/codex#24135, where the reporter says the only workaround is --dangerously-bypass-approvals-and-sandbox, which is the flag you don’t want in a daemon.

Is --dangerously-bypass-approvals-and-sandbox safe in CI?

OpenAI’s docs label it elevated-risk, and it removes both the approval gate and the sandbox at once. If the job touches anything real (credentials, deploy targets, MCP servers with write scopes), you have an unattended agent with no gate and no container. If you must run it, treat the job’s environment as the whole security boundary: minimal credentials, an isolated runner, and a record of what the agent did that the agent didn’t write.

How do I approve Codex MCP tool calls non-interactively?

You can’t approve them mid-run. There is no approval channel in codex exec, and config keys like mcp_approval_policy don’t exist. What works is removing the need for the question: pin the sandbox to workspace-write, keep a PreToolUse hook on the call path, and decide ahead of time which calls you would have approved. Then an unlisted call becomes a logged deny instead of a cancelled run or a blanket bypass.

Do Codex hooks still run in headless mode?

Yes. In sandboxed non-interactive modes PreToolUse and PostToolUse still fire, the same way Claude Code’s hooks do under its skip-permissions flag. A hook can still deny a call with a reason the model sees, even with no human attached.

Where to read more

Running Codex? One command adds a hook for shell, apply_patch and MCP calls. Each call is recorded, and a force-push, destructive SQL or curl | sh is blocked until you approve it on the console or from the email.

macOS · Linux · WSL
curl -fsSL https://agenticcontrolplane.com/install.sh | bash
Windows · PowerShell
irm https://agenticcontrolplane.com/install.ps1 | iex

What the installer writes  ·  Codex guide  ·  free up to 5 agents

Share X HN LinkedIn
Get the next data drop
What agents actually cost, new tool-surface captures, and the occasional incident post-mortem — sent when we publish something worth your inbox, not on a schedule. Unsubscribe anytime.
Share: Twitter LinkedIn
Related posts

← back to blog