codex exec: no way to allow MCP tool calls non-interactively without --dangerously-bypass-approvals-and-sandbox
Summary
In codex exec (non-interactive), MCP tool calls are auto-cancelled because stdin is closed and no config key I can find suppresses the approval prompt. The only working bypass is --dangerously-bypass-approvals-and-sandbox, which also disables -s read-only sandboxing. Asking: what's the right way to authorize MCP tool calls in codex exec while keeping -s read-only in place?
Environment
codexv0.130.0 (Homebrew, macOS arm64)- Auth: ChatGPT subscription via
codex login
Repro
Minimal STDIO MCP server with one tool:
# /tmp/spike_mcp_server.py
from mcp.server.fastmcp import FastMCP
server = FastMCP("spike")
@server.tool()
def echo_hello(name: str) -> str:
return f"hello {name}"
server.run()
Register it and call it from codex exec:
SPIKE_HOME=$(mktemp -d)
cp ~/.codex/auth.json "$SPIKE_HOME/"
codex --help >/dev/null # ensure binary works
CODEX_HOME="$SPIKE_HOME" codex mcp add spike -- /opt/homebrew/bin/python3 /tmp/spike_mcp_server.py
# Verify registered
CODEX_HOME="$SPIKE_HOME" codex mcp list
# Name Command Args Env Cwd Status Auth
# spike /opt/homebrew/bin/python3 /tmp/spike_mcp_server.py - - enabled Unsupported
# Call it
CODEX_HOME="$SPIKE_HOME" codex exec --color never \
--skip-git-repo-check -s read-only \
"Use the spike echo_hello tool with name=test and report what it returned." \
</dev/null
Observed
mcp: spike/echo_hello started
mcp: spike/echo_hello (failed)
user cancelled MCP tool call
The MCP child process IS spawned (verified via RUST_LOG=info: MCP server stderr (/opt/homebrew/bin/python3): [spike_mcp_server] startup pid=...), but the tool call is auto-cancelled — presumably because stdin is closed so the approval prompt's reader gets EOF and codex interprets that as "user declined".
What I tried (none of these suppress the approval)
Tried each of these in $CODEX_HOME/config.toml:
approval_policy = "never"
default_tools_approval_mode = "never"
tools_require_approval = false
mcp_approval_policy = "never"
trusted_mcp_servers = ["spike"]
[projects."<spike-cwd>"]
trust_level = "trusted"
[mcp_servers.spike]
approval_policy = "never"
(approval_policy and default_tools_approval_mode are accepted by codex without errors — session header shows approval: never — but neither prevents the MCP-call cancellation. The other keys are silently ignored.)
I also tried --ignore-user-config + -c mcp_servers.spike.command=... CLI overrides; the MCP server didn't even register that way.
What does work
--dangerously-bypass-approvals-and-sandbox makes the call succeed:
mcp: spike/echo_hello (completed)
{"result":"hello test"}
But this flag also disables -s read-only, so it's not a viable production posture for a daemon that needs to keep filesystem reads sandboxed.
What I'm trying to do
I'm migrating a personal-AI daemon (codebase: github.com/gsingal/hanuman, issue #143) from claude -p to codex exec so it doesn't burn API credits. The general-agent layer needs to call our first-party STDIO MCP server (read-only Google tools + a frozen-URL allowlist enforced server-side in Python) while keeping -s read-only codex sandboxing so the model can't read arbitrary files outside the per-call scratch dir.
Ask
What's the supported config to authorize MCP tool calls in codex exec without --dangerously-bypass-approvals-and-sandbox?
Specifically: is there a way to say "trust this MCP server's tool calls without prompting" that works alongside -s read-only?
If this isn't currently supported, would you accept a config key proposal like [mcp_servers.<name>] auto_approve_tools = true (or a global default_mcp_tools_approval_mode = "never") for the same use case other agent-framework users will hit when calling codex non-interactively?
Why I think this matters beyond my use case
Any non-interactive use of codex exec with custom MCP servers (cron jobs, headless daemons, CI-driven agents, evaluation harnesses) hits this same wall. The --dangerously-bypass-approvals-and-sandbox flag's name (correctly) discourages using it in production, but right now it's the only path to a working non-interactive MCP-tool call.
Happy to provide more repro detail, RUST_LOG output, or test a candidate fix.
Proposed Solution: MCP-Specific Approval Config for Non-Interactive Mode
Root Cause
MCP tool calls go through the same approval prompt as other tools. When stdin is closed (non-interactive), EOF is interpreted as "user declined". No config key bypasses MCP approval while keeping sandbox active.
Fix
- Add
[mcp_servers.<name>] auto_approve_tools = trueconfig key - Respect
approval_policy = "never"for MCP calls (currently only affects non-MCP) - Split
--dangerously-bypass-approvals-and-sandboxinto--bypass-approvals+--bypass-sandbox
fn handle_mcp_tool_call(call, config) {
let auto_approve = config.mcp_servers.get(&call.server_name)
.map(|s| s.auto_approve_tools).unwrap_or(false);
if auto_approve || config.approval_policy == Never {
return execute_tool_call(call);
}
prompt_for_approval(call)
}
Full solution: solutions/codex-24135-mcp-tool-calls-non-interactive-fix.md
I think there is one safety detail worth making explicit if Codex adds an MCP-specific non-interactive approval path.
For headless codex exec, I would avoid making this only a broad boolean like auto_approve_tools = true. The production-safe shape is closer to:
- keep the filesystem/network sandbox setting independent from MCP approval
- trust a server by stable identity: configured name, transport, command/url, cwd, and env-file boundary
- trust individual tools by namespaced key, for example
spike.echo_hello, not just raw tool name - store a reviewed discovery snapshot from
tools/list - re-enter review if a tool is added, removed, or its metadata/schema changes
- treat server annotations such as read-only/destructive/idempotent as advisory inputs, not proof
- in non-interactive mode, fail closed if no reviewed allow entry matches
That would preserve the thing this issue is asking for: first-party MCP tools can run in codex exec -s read-only without stdin approval prompts, while the user does not have to use the broader dangerous bypass flag.
I made a small free helper for this exact review artifact while testing MCP launch/security workflows:
https://github.com/kayalopez/ai-agent-launch-tools/releases/tag/v0.1.7
It turns non-sensitive tools/list JSON into an allow / ask / deny matrix and emits a snapshot digest plus per-tool metadata digests. It can also print a Codex config.toml review snippet: allow -> approval_mode = "approve", ask -> approval_mode = "prompt", and deny -> disabled_tools, without changing sandbox settings. The useful bit for this issue is the acceptance-test pattern: run discovery, approve exact tool keys, then verify a changed tools/list snapshot forces review instead of inheriting approval silently.
No tool calls are executed by the helper; it only classifies pasted/exported metadata.
For non-interactive codex exec, I would keep sandbox policy and MCP approval policy completely separate.
The unsafe shape is a broad switch that means "auto-approve MCP tools" and accidentally becomes equivalent to bypassing the sandbox. The safer shape is a scoped MCP approval policy that can be evaluated without stdin:
- MCP server identity;
- tool name;
- canonical args digest or args pattern;
- read/write/destructive classification;
- allowed workspace or resource scope;
- network scope, if relevant;
- expiry;
- policy id;
- decision: allow, deny, require_interactive.
Then headless execution can work like this:
- if a pending MCP call matches an explicit allow rule, execute under the existing sandbox;
- if it matches deny, return a terminal denied tool result;
- if it requires interactive approval and stdin is closed, fail closed with a clear approval-required result;
- never make
--dangerously-bypass-approvals-and-sandboxthe only path to non-interactive MCP.
Regression tests I would want:
- read-only sandbox remains active while an allowed MCP tool runs;
- write/destructive tool is denied without a matching policy;
- changed args do not reuse a prior allow decision;
- closed stdin produces a visible approval-required result, not silent cancellation;
- policy expiry invalidates future headless calls.
That gives automation a safe path without making approval bypass and sandbox bypass the same lever.
This is exactly the kind of problem I'm trying to validate.
I've been building a small Python authorization layer that sits outside the agent and evaluates individual tool calls before execution, rather than having to choose between interactive approval and effectively bypassing the safety layer.
The interesting use case seems to be headless/CI agents where you still want deterministic permissions and possibly approval policies without a human sitting at stdin.
If you've still got the use case around, I'd be happy to give you the prototype to test against your MCP setup.
I'd be especially interested in whether it actually solves the gap or just adds another layer you wouldn't want in the stack.
A useful test would keep the read-only sandbox fixed and vary only interactive versus noninteractive execution. An allowed read and an explicitly denied write should give separate outcomes, with a server counter confirming what ran. Does the cancellation occur before any request reaches the MCP server?
Codex under a dedicated Windows account: unattended operation and verifiable code changes — does anyone have a working integration?
- Date: 2026-10-13 · Authors: Chasper (desktop) and Claude, corrected against measurements · Release: Joe
- Purpose: question to developers of comparable Codex integrations (GitHub Discussions of the projects named in the analysis, openai/codex Discussions)
- German original:
Codex_Integrationsanfrage_20261013_de.md
Hello everyone,
we are building AUOJI OrderBoard, a task board for software development based on .NET and WinUI 3. Five local AI agents are meant to work together in it. Each agent runs under its own standard Windows user account in its own working copy and receives its assignments through an MCP server of the board.
Claude Code has been working in this system for a month without comparable problems. We have now spent about three weeks working intensively on the Codex integration and its troubleshooting.
Our environment and integration:
- Windows 11 Pro 25H2
- Codex CLI 0.154.0
- Invoked via
codex exec --json - Configuration passed at start:
mcp_servers.orderboard.url, an explicitapproval_mode = "approve"for each required tool,sandbox_mode = "danger-full-access"andapproval_policy = "never" - For code changes, our service starts a separate Codex child process on demand under the same Windows account.
What works: Codex has been reading and writing our board documents through MCP tools repeatably for weeks. Communication and MCP-based document editing are therefore working in principle.
Where we are stuck:
1. Operation without a logged-on desktop session
Our current scheduled task uses InteractiveToken. Without a logged-on session of the agent account, our start service refuses the start with the Task Scheduler's message that no logged-on Windows session with a user token exists for that SID.
We have not yet achieved unattended operation without that session. Claude Code runs under the same conditions as a background process in session 0, without a logged-on desktop session.
In addition, we are investigating the profile requirements of the Codex sandbox. Issue openai/codex#17458 describes uninitialized sandbox user profiles, including a reproduction with CLI 0.154.0. Whether that issue explains our difficulties with operation without a desktop session has not been proven yet.
2. MCP approvals in non-interactive operation
In our tests the required MCP calls only worked once we set an explicit approval_mode = "approve" per tool. With that configuration they work. The general setting approval_policy = "never" alone was not sufficient in our flow.
We would like to know whether other integrators take the same route or use another supported mechanism. The discussion in issue openai/codex#24135 is related.
3. No verified code changes by the separate execution agent
Since 30 September 2026 our logs contain 467 starts of the execution agent. For that period we cannot prove a single successful code change by it.
Our own logs contain 42 errors:
- 38 messages "no account SID registered" on 30 September and 1 October;
- four messages "Pipe is broken" since 10 October.
These errors sit in our integration and communication layer. We do not attribute them to Codex without further evidence.
Our service does not log explicit success messages, only warnings on failure. From the absence of further warnings we therefore cannot infer a successful programming run. The result of the Codex child process currently flows back only into the calling Codex session; our service logs lack a complete record of its tool execution and its result.
The working copy currently has no pending changes. All Codex backups in it since 1 October are owned by the sandbox account CodexSandboxOffline; they therefore come from the Codex desktop app in the developer's logged-on session, not from the child process under the agent account. There is not a single file from the child process. That is our finding so far, not a complete record of all file operations.
Our questions to developers of comparable integrations:
- Do you run Codex on native Windows as a service or scheduled task under a dedicated user account, without a logged-on desktop session? With which start mode and which profile initialization?
- Which exact Codex version do you use, and do you use
execor the app server? - How do you handle MCP approvals in unattended operation?
- With separate Codex execution processes, how do you capture tool calls, errors and results so that you can distinguish actually applied code changes from merely completed agent runs?
We are looking for experience from a working integration and would very much appreciate an exchange. We can put together a sanitized start command and relevant diagnostic excerpts.
History
- 2026-10-13 · Translated from the German version after Joe's release; wording follows the German text paragraph by paragraph.
Additional headless/Slack-hosted MCP write approval use case for this open issue (observed with Codex CLI 0.160.0):
A noninteractive codex exec host has an existing authenticated human approval UI, but a write-capable MCP tool requires approval. Under approval_policy=never, Codex returns MCP tool call requires approval, but approval policy is never before dispatch. This is correctly fail-closed, but currently there is no supported request/response channel for the host to obtain and relay a one-time decision. Allowing the entire tool via approval_mode=approve is too broad when the same tool can write to different repositories/branches/paths.
Feature request: an opt-in, versioned host-mediated per-call approval protocol for codex exec, independent of sandbox configuration. An outbound request would bind execution ID, MCP server/tool identity, canonical arguments digest, a one-time request ID and expiration; the host replies allow/deny for exactly those unchanged arguments. Missing capability, deny, disconnect, timeout, restart and replay should all fail closed with zero MCP dispatch. Preserve CLI sandbox and no implicit always/session approvals. If possible, include a way for the host to render a complete operation preview and enforce its own resource-specific authorization before approving.
Suggested regression tests: mock MCP server with call counter; approval for exact args dispatches once; denied/stale/changed/replayed/missing reply dispatches zero times; start/resume safe, no bypass of sandbox or underlying managed policy. This should not introduce any alternate transport or assume that tool-level allowlisting enforces individual resource scope.
Related earlier report #29857 concerned plugin identification/config; this is a distinct request for explicit human approval in headless exec when the tool must remain approval-gated. Does a currently supported exec host-approval API exist, or is this an upstream capability gap?
No credentials, real backend data or destructive calls were used to reproduce the local policy failure.
Implementation spike against rust-v0.162.1 and current main, following the host-approval request above:
We found an existing internal request/response route in codex exec: InProcessAppServerClient, InProcessServerEvent::ServerRequest and client.resolve_server_request() in codex-rs/exec/src/lib.rs. However, handle_server_request() currently cancels elicitation/rejects input requests rather than forwarding them to an external CLI host. The core refusal remains present in 0.162.1 and main. No supported exec host approval interface was identified. This suggests an opt-in framed stdin/JSONL adapter atop the existing internal app-server request loop, not a new daemon/transport or blanket auto-approval.
Important integrity pitfall: handle_approved_mcp_tool_call() uses rewrite_mcp_tool_arguments_for_openai_files() after approval, in PreparedMcpCall::call_with_preparation() (source). An approval bound only to the pre-rewrite argument digest may authorize a different final tool payload. A minimal first implementation should either support only proven no-rewrite invocations or freeze and present final prepared arguments before the approval request, proving preparation cannot have side effects.
Minimal proposed PR scope:
- Explicit opt-in, versioned host capability in
exec/src/cli.rs; framed stdin for handshake, prompt, one-shot decisions (the current prompt-then-EOF mode stays default), framed requests over stdout; stderr diagnostic only. - Route a dedicated MCP-only approval request through the existing
InProcessAppServerClientevent loop andresolve_server_request(), with finite timeout/cancellation. Keepapproval_policy=neverbehavior for all non-opted-in cases. - Bind execution, thread, turn, call ID, server/tool identity and canonical final argument digest; approve one immutable invocation, deny/EOF/replay/stale or changed payload -> zero MCP dispatch. No remembered/session/always grants.
- Add mock-MCP tests to
codex-rs/exec/tests/suite/mcp_host_approval.rsand core approval tests (zero or one invocation counter, start/resume, failure/replay, argument rewrite boundary).
This is an unimplemented proposal, not a tested patch. Could maintainers confirm whether this is an acceptable codex exec extension point and, especially, where an immutable prepared-call boundary should live? We intend to keep the sandbox and to avoid requiring a switch to the public App Server transport.
I tested this on Codex CLI 0.155.1 and 0.169.0, with a six-tool MCP server that logs every call it receives, and re-ran the main cases on 0.169.1. Some answers for this thread:
The refusal happens before the server is called. In codex exec with approvals at never, none of the refused calls appeared in the server's call log. So there's nothing to debug on the server side.
Which tools get refused. In the default auto approval mode on 0.169.0, a tool runs without approval if it sets readOnlyHint: true, or if it sets both destructiveHint: false and openWorldHint: false. A missing hint counts as the risky value (readOnlyHint false, destructiveHint and openWorldHint true), so a tool with no annotations is refused. Before 0.169.0, destructiveHint: true won over readOnlyHint: true (0.155.1 refused that pair).
Ways to allow MCP calls in codex exec without --dangerously-bypass-approvals-and-sandbox (all ran on both versions):
- One tool:
approval_mode = "approve"under[mcp_servers.NAME.tools.TOOL]in config.toml. - One server:
default_tools_approval_mode = "approve", ideally withenabled_toolslisting the tools you've read. codex exec --approve-for-me, which sends approval requests to the automatic reviewer. It also switches to the workspace-write sandbox, and 0.169.0 rejects it together with--sandbox.- If you wrote the server, annotate each tool accurately. The
autorule above then lets the read-only ones through with no config.
What didn't help: approval_policy = "on-request" on its own (the exec header still printed approval: never), default_tools_approval_mode = "writes" (only readOnlyHint: true tools ran), and changing the sandbox.
These all approve in advance. A per-call, host-side approval route for headless runs, as discussed above, is still a separate ask.
I wrote up the full test, with the server and the commands to re-run it: MCP Tool Call Requires Approval, but Approval Policy Is Never: Cause and Fix