Skip to content

fix(executor): Codex honours tool_policy (read-only sandbox, refuse what it cannot express) - #2624

Merged
sunholo-voight-kampff merged 1 commit into
devfrom
fix/codex-honours-tool-policy
Dec 2, 2026
Merged

sunholo-voight-kampff merged 1 commit into
devfrom
fix/codex-honours-tool-policy

Conversation

@sunholo-voight-kampff

Copy link
Copy Markdown
Collaborator

What

The Codex executor now applies Task.AllowedTools (the coordinator's resolved tool_policy) instead of always launching with --dangerously-bypass-approvals-and-sandbox. Before this, the exec path never read AllowedTools, so a question task (always given a read-only list) or an agent with a restricted tool_policy ran on Codex with an unrestricted shell. The daemon adapter refused every allowlist outright.

One function, resolveCodexPermissions in internal/executor/codex/permissions.go, now makes the decision for both launch paths:

AllowedTools exec argv daemon thread/start
nil (full / no policy) --dangerously-bypass-approvals-and-sandbox (unchanged) sandbox: danger-full-access, approvalPolicy: never (unchanged)
only read-only names: Read, Grep, Glob, AilangRead, AilangCheck, BuiltinsSearch, ExamplesSearch, WebFetch, WebSearch --sandbox read-only -c approval_policy="never" -c web_search="live"|"disabled", no bypass sandbox: read-only, approvalPolicy: never, config.web_search
any other name (Write, Edit, Bash, AilangWrite, AilangEdit, AilangRun, AilangCLI, MicroragSearch, QuotaReport), or [] refused before Codex starts, error names the tools same refusal
  • Web tools. Codex's web_search is a hosted tool that runs on the provider's side, not in the local sandbox, so it works under read-only while the shell keeps no network. It is live when the list has WebFetch or WebSearch (Codex has no separate fetch tool; live can open pages), and disabled otherwise. Question tasks therefore keep web search.
  • No workspace-write mapping. It is not an exact match: without Bash it would give the agent a shell that can write; with Bash it is narrower than Bash elsewhere (writes only under the workspace, no network). Refusing is what the daemon adapter, motoko and pi already do.
  • Empty list (for example a question task for an ailang_only agent, question ∩ ailang_only = []) is refused. Codex always has a shell, so it cannot run with no tools.
  • Known widening. The read-only sandbox can read the whole host, which is wider than AilangRead's policy root. It still cannot write, reach the network, or escalate (approval_policy="never" rejects escalation requests).
  • Result.ToolPolicy now records the sandbox each Codex run used: <cli default>, or e.g. sandbox:read-only, approval:never, web_search:live. Before, it was nil (unmeasured).
  • Task.MCPServers (eval browser benchmarks only) are unchanged. The caller grants them explicitly.

Flags verified against the installed CLI (codex-cli 0.173.0), no model call

  • codex exec --help lists -s, --sandbox <read-only|workspace-write|danger-full-access>. exec has no -a, so the approval policy is passed with -c approval_policy=....
  • With an empty CODEX_HOME, codex debug prompt-input -c web_search="bogus" (and the same for sandbox_mode and approval_policy) fails with unknown variant. Each error lists the accepted values (disabled|cached|indexed|live, read-only|..., never|...), which shows all three keys exist and are validated. With the read-only settings, the rendered model prompt says: "sandbox_mode is read-only: The sandbox only permits reading files. Network access is restricted."
  • With no credentials, the exact read-only argv was run through codex exec. It parsed and reached turn.started, then failed with 401 because there was no auth, so nothing was spent.
  • codex sandbox -P :read-only -- sh -c '...': the read succeeded, the write failed with Operation not permitted, and curl failed with Could not resolve host.

Launch sites (grep -rn dangerously-bypass internal/ cmd/)

  • internal/executor/codex/mcp_config.go buildCodexArgs (exec and streaming): now goes through resolveCodexPermissions.
  • internal/executor/codex/daemon_execution.go: the blanket refusal is replaced with the same decision. thread/start already carries sandbox and approvalPolicy, and web_search rides in its config.
  • ExecuteStreaming resolves before either runtime branch, so AILANG_CODEX_RUNTIME=daemon and cli refuse identically.
  • The Cloud Run job (coordinator_cloud_executor.go) and the eval harness reach Codex through the same executor.
  • Not tool_policy-driven and unchanged: cmd/ailang/mission_codex_exec.go (mission CLI, defaults to read-only; the bypass is an explicit operator flag), internal/mission/quorum/codex_reviewer.go (always read-only), and internal/mission/codex_app_server_quota.go (quota probe). There is no separate codex-agy twin: agy is its own executor.

Live-lane impact

The coordinator config (ailang-multivac config/config.cloud.yaml) has two Codex agents, sprint-planner (codex) and sprint-executor (codex-go). Neither sets tool_policy, so their normal tasks are unchanged (full). Question-kind tasks routed to them now run read-only with web search instead of with full access. No Codex agent declares tool_policy. The local ~/.ailang/config.yaml has no Codex agents.

Agents that will now refuse to start

None in the coordinator agent config. Code paths that would now refuse on Codex:

  • Mission role-run evaluator on Codex (internal/mission/dispatch/run.go, AllowedTools = [Read, Bash]): refused, naming Bash. On the rig's AILANG_CODEX_RUNTIME=daemon this path was already refused by the old daemon check, so only a cli-runtime Codex evaluator changes. To run one, route the evaluator to claude or pi, or drop its allowlist (not recommended).
  • Any future agent or eval run with tool_policy: ailang_only or lean on Codex: refused, naming the write and shell tools. Fix: use provider: pi for those lanes, or clear tool_policy.

Tests

internal/executor/codex/permissions_test.go:

  • TestBuildCodexArgs_NilToolPolicyKeepsBypass: nil keeps the exact byte-compatible argv.
  • TestBuildCodexArgs_QuestionToolsRunReadOnly: the exact read-only argv, with no bypass.
  • TestBuildCodexArgs_ReadOnlyWithoutWebDisablesSearch
  • TestBuildCodexArgs_RefusesWhatReadOnlyCannotExpress: ailang_only, lean, mission evaluator, a write tool, and the empty list. Each asserts the daemon gives the identical error.
  • TestDaemonExecOptions_SharesTheExecDecision
  • TestDaemonProtocolSendsReadOnlySandbox: thread/start on the wire carries read-only, never and web_search.
  • TestExecuteStreamingHonoursToolPolicy: a fake codex records its argv. A question task runs read-only and banks its ToolPolicy. A shell-tool task is refused and codex never launches, under both the cli and daemon runtimes.

Mutation-tested with scratch copies. All five mutants failed the suite: always bypass, never refuse, daemon hardcoded to full access, web search always off, and empty list allowed.

Gates: make test-changed, make lint, make check-file-sizes, make check-boundaries, make check-changelog.

🤖 Generated with Claude Code

…hat it cannot express)

The Codex exec path never read Task.AllowedTools and always launched with
--dangerously-bypass-approvals-and-sandbox, so question tasks and restricted
tool_policy agents ran with a full shell. The daemon adapter refused every
allowlist outright.

resolveCodexPermissions (permissions.go) now decides for both paths:
- nil: unchanged full access (bypass flag / danger-full-access)
- only read-only names: --sandbox read-only, approval_policy "never", no
  bypass; WebFetch/WebSearch enable the hosted web_search, else disabled
- any write/shell tool, or an empty list: refused, naming the tools

The daemon's thread/start carries the same sandbox and approval policy.
Result.ToolPolicy banks the sandbox each run used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sunholo-voight-kampff
sunholo-voight-kampff merged commit 27d34f0 into dev Dec 2, 2026
24 of 25 checks passed
@sunholo-voight-kampff
sunholo-voight-kampff deleted the fix/codex-honours-tool-policy branch December 2, 2026 16:08
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.

1 participant