Skip to content

fix(codex): approve installed MCP servers under the local sandbox - #362

Merged
zpzjzj merged 3 commits into
alibaba:mainfrom
karanb192:fix/codex-mcp-approval
Nov 3, 2026
Merged

zpzjzj merged 3 commits into
alibaba:mainfrom
karanb192:fix/codex-mcp-approval

Conversation

@karanb192

@karanb192 karanb192 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On the none runtime, skill-up runs the first Codex turn with --sandbox workspace-write. With Codex CLI 0.166.0, the #358 repro rejects the installed mock's tool call with MCP tool call requires approval, but approval policy is never.

This PR approves tool calls for the installed server names with a per-server Codex config override on the run command. The sandbox stays on. Other server names receive no override.

Related issues

Closes #358

Changes

  • internal/agent/codex.go:
    • InstallMCP records the names of the servers it installed, keyed by the runtime's workspace. Cases share one agent and run concurrently, so each case keeps its own set (replaced on every install, emptied when a case installs none), guarded by a mutex.
    • When Run uses the process sandbox (the none runtime without bypass_sandbox), it adds -c 'mcp_servers.<name>.default_tools_approval_mode="approve"' for each server recorded for its workspace. Runs that already bypass approvals (Docker, OpenSandbox, bypass_sandbox: "true", and the resume path) are unchanged.
    • A server name that a dotted -c path cannot address (anything outside ^[A-Za-z0-9_-]+$) is skipped with a warning. Codex fails to load its config for such an override.
  • internal/agent/codex_test.go:
    • one shared agent, three runtimes installing different server sets (one of them none) concurrently; each run command must approve exactly its own servers, keep --sandbox workspace-write, and never carry a dotted name;
    • one reused workspace installing shop, then docs, then nothing; each run approves only the latest set;
    • runs that bypass approvals (bypass_sandbox, OpenSandbox) get no override.
  • docs/guide/writing-evals.md: the bypass_sandbox row for codex now says installed MCP servers are approved under the default none sandbox, and names the server-name restriction.
  • CHANGELOG.md: one line under Unreleased, Fixed.

Test plan

  • make test passes
  • make verify passes with zero findings on the rebased head.
  • go test -tags e2e ./e2e passes on the rebased head, with agent CLIs absent from PATH.
  • The shared-agent and reused-workspace tests fail on the first commit alone and pass with the branch; they also pass with -race.
  • Manual, Codex CLI 0.166.0 with codex exec --sandbox workspace-write: the same MCP call fails without the override and completes with it, nothing else changed.
  • Manual, before this rebase, the bug(codex): local runs reject MCP tool calls with "approval policy is never" #358 repro (environment.type: none, no bypass_sandbox, existing login): the mcp_tool_call completed and the answer contained the mocked status, with the session's sandbox policy still workspace-write. That run scored 50% because tool_called missed the call. The transcript fix from fix(codex): keep code-tool calls in session transcripts #361 is now in the base; I have not repeated the live Codex repro after rebasing.

Notes for reviewers

  • Parallel cases still share Codex's config file on the none runtime. A same-named server installed by another case can replace the definition before execution. The approval sets are per workspace; the installed definitions are not. The isolation design remains open in bug(codex): mocked MCP servers are written into the user's global ~/.codex/config.toml and left there #360 and the review thread on this PR.
  • I checked the override against an MCP server defined in config.toml (as codex mcp add writes it): it merges, and the server keeps its transport. An override for a server that is not in the config would create a server with no transport and stop Codex from loading, so only installed servers get one.
  • The per-workspace sets are never deleted after a case ends; each holds a few names, so I left cleanup out. A user who points several cases at one existing workspace shares one set, as those cases already share one Codex setup.
  • Skill-up's default Codex pin is 0.80.0. From its source, RawMcpServerConfig does not deny unknown fields, so the extra key is ignored there. I did not run 0.80.0.
  • default_tools_approval_mode = "approve" approves every tool of that server, including ones a real server marks as destructive. For servers skill-up installs for an eval that matches what the Docker and OpenSandbox runtimes already allow.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T15:42:59.267775Z 2864392 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2864392c31

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/agent/codex.go Resolved
On the none runtime Codex runs with --sandbox workspace-write and the
exec approval policy "never", so it rejected every call to an MCP server
skill-up installed: "MCP tool call requires approval, but approval
policy is never".

Record the servers InstallMCP added and pass
-c mcp_servers.<name>.default_tools_approval_mode="approve" for each on
the first-turn command when the process sandbox is used. The sandbox
stays on, and servers from the user's own Codex config are not approved.
Names a dotted -c path cannot address are skipped with a warning, since
Codex would fail to load its config.

Closes alibaba#358
Cases share one CodexAgent and run concurrently, so a single set of
installed server names leaked approval overrides into other cases. Keep
the set per runtime workspace, replace it on every install, and test the
shared-agent pattern. Document the server-name restriction.
@karanb192
karanb192 force-pushed the fix/codex-mcp-approval branch from 2864392 to 53af207 Compare November 3, 2026 06:13
@zpzjzj
zpzjzj added this pull request to the merge queue Nov 3, 2026
Merged via the queue into alibaba:main with commit 2405922 Nov 3, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(codex): local runs reject MCP tool calls with "approval policy is never"

2 participants