Skip to content

Headless codex exec blocks side-effecting MCP tools under read-only/workspace-write sandboxes #392

Description

@kamilio

Summary

When spawning codex non-interactively via spawn/spawn.pretty with mode: "read" or mode: "edit", the agent is unable to invoke side-effecting MCP tools — the tool call is silently canceled before it reaches the MCP server. Only mode: "yolo" (codex -s danger-full-access) lets MCP tool calls through.

This forces any agent that must call an MCP tool (e.g. to post a Slack reply, file a ticket, etc.) to run in full-access mode, even when the agent only needs a read-only filesystem for its actual work.

Mode → codex flag mapping (current)

From providers/codex.js:

read:  ["-s", "read-only"]
edit:  ["-s", "workspace-write"]
yolo:  ["-s", "danger-full-access"]

codex exec has no --ask-for-approval prompt path (it's headless), so under read-only/workspace-write a side-effecting MCP tool call is auto-canceled rather than executed.

Reproduction

Spawn codex via codex exec with an MCP server configured (-c mcp_servers.<name>.command=...) and a prompt instructing it to call one of that server's tools. Observe the tool result per sandbox mode:

codex sandbox (-s) MCP tool call
read-only canceled / blocked
workspace-write canceled / blocked
read-only + -a never errors out (exit 2)
danger-full-access executes

The MCP server itself is correct: driving the same server with a standard MCP client (@modelcontextprotocol/sdk Client + StdioClientTransport) executes the tool in ~14ms. The gating is entirely in codex's headless sandbox/approval handling.

Impact

A read/edit agent that needs to call an MCP tool fails silently — the model "calls" the tool, codex cancels it, and the run completes without the side effect ever happening. There's no error surfaced to the caller from codex's side.

Request

Provide a way to run codex headlessly with a restricted filesystem sandbox (read-only / workspace-write) while still permitting configured MCP tool calls — e.g.:

  • an approval-policy/MCP-trust option that auto-approves configured MCP servers' tools under read-only/workspace-write, or
  • treating configured MCP tools as out-of-sandbox (they're trusted, caller-configured servers), or
  • at minimum, surfacing a clear error when an MCP tool call is canceled due to sandbox policy instead of silently dropping it.

Today we have to set mode: "yolo" for any codex agent that posts to Slack, which over-grants filesystem/network access purely to unblock the MCP reply tool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions