Custom agent sandbox_mode = "read-only" is ignored when spawned from codex exec (child inherits workspace-write)
What version of Codex CLI is running?
0.153.4
What happened?
A project-scoped custom agent (.codex/agents/<name>.toml) that sets sandbox_mode = "read-only" runs with the parent session's workspace-write sandbox when spawned from a non-interactive codex exec session.
The custom agent's configured model is honoured (7 of 7 agents matched), but sandbox_mode is not (2 of 2 read-only agents ran workspace-write).
Evidence comes from the spawned child thread's own session rollout JSONL (turn_context.sandbox_policy.type), not from the agent's self-report:
code_explorer: agent_role=code_explorer model=gpt-5.6-terra sandbox=workspace-write (configured: read-only)
planner: agent_role=planner model=gpt-5.6 sandbox=workspace-write (configured: read-only)
A write via exec_command inside the spawned read-only agent succeeded (exit 0, file created in the working tree).
Steps to reproduce
- Create
.codex/agents/reader.tomlin a trusted project:name = "reader" description = "Read-only test agent" developer_instructions = "Try to create a file named probe.txt, then report." sandbox_mode = "read-only" - From the project root, run
codex exec(which runsworkspace-write) and prompt it to spawn thereaderagent. - Check the child thread's rollout in
~/.codex/sessions/...:turn_context.sandbox_policy.typeisworkspace-write, andprobe.txtexists.
What did you expect?
The spawned agent runs under read-only, as its file sets, and the write is refused. At minimum, a child should never get a broader sandbox than its agent file declares.