ADR 0002: Restricting the Codex and Cursor CLIs to the review tool set¶
Status: accepted (milestone 1). Date: 2026-11-28. Updated 2026-11-29: the agents run through their SDKs (below).
Update 2026-11-29: agent SDKs¶
The three adapters now drive their agents through the official Python SDKs (claude-agent-sdk, openai-codex,
cursor-sdk; design: docs/specs/2026-11-29-agent-sdks-design.md). The isolation list in Context still holds, with
these changes. The sections after this one describe the CLI-era adapters and are kept as the record of why Codex and
Cursor are experimental.
- reviewloop marks itself non-dumpable (
prctl(PR_SET_DUMPABLE, 0), Linux) before an agent runs, so an agent's read tools cannot open/proc/<reviewloop pid>/environ, which lists the tokens reviewloop was started with. - Every SDK starts its child process from the whole parent environment. Each adapter points the SDK at an env-clearing
launcher in the throwaway HOME (
install_env_launcher), so the child sees only the adapter's scrubbed environment plus the SDKs' own non-secret protocol variables. Credentials are in a 0600 env file the launcher sources, never in argv. The launcher starts the agent in its own process group; reviewloop kills that group after each run and on timeout. - Codex:
codex app-serverinstead ofcodex exec. Same-coverrides, plusfeatures.*=falsefor the browser, computer-use, image, plugin and MCP-install tools the app server enables by default. The thread usesApprovalMode.deny_all(the SDK defaultauto_reviewwould overrideapproval_policy="never"), the read-only sandbox andephemeral.OPENAI_API_KEYgoes over the RPC (account/login/start) withcli_auth_credentials_store="ephemeral": the app server does not readCODEX_API_KEY, and the key is in neither the environment nor a file.--ignore-user-configand--ignore-ruleshave no app-server equivalent; the throwaway HOME has no user config or rules to ignore. System-level Codex config (/etc/codex/) is still read; the image has none, but a self-hosted runner with one applies it. reviewloop writes the final message to the output file. - Cursor now runs without a shell. The SDK takes whole tool names only and ignores the
cli.jsonallow and deny rules, so it cannot hold a shell to the four git commands. The agent getsread,grep,globandlsonly (no shell, no edit, no web, no MCP);CURSOR_API_KEYgoes over the RPC. Cursor therefore reviews without git history, and the shell-matcher bypasses described below no longer apply. It stays experimental: with its sandbox off, its read tools still open absolute paths outside the copy. reviewloop writes the final message to the output file.
Context¶
Spec 8.2 limits a review agent to read tools, the shell commands git log, git blame, git show and git diff,
and one writable file, .reviewloop/out/<step>.json. Each adapter maps that to its CLI's own permission mechanism.
reviewloop also enforces isolation itself, whatever the CLI does (see src/reviewloop/agents/isolation.py):
prepare_sandbox: a link-free clone with no remotes, credentials, hooks or committed agent config.- A throwaway HOME per run, deleted afterwards.
- The git guard (
install_git_wrapper) first on PATH. The guard, not the CLI, enforces git options and paths (ruling R17). - An allowlist-scrubbed environment: the adapter's own model credential,
PATH,HOME, and locale/temp variables. - A snapshot check after every run: any change besides the output file fails the step.
- A process-group kill on timeout and after exit.
strip_checkout_credentials(ruling R31): before the first agent run, the init step removes git credentials from the CI job's own checkout and from every submodule gitdir under.git/modules/:- userinfo in remote and push URLs and in proxy URLs (
http.proxy,http.<url>.proxy,remote.*.proxy); url.<base>sections whose name carries userinfo, and everyinsteadOf/pushInsteadOfrewrite;http.*.extraheader,credential.*, includes,core.askPassandcore.sshCommand.
reviewloop talks to the VCS through API tokens and never fetches or pushes, so the job needs none of them after checkout.
The spec says a CLI that cannot be held to this tool set moves to milestone 1.5 instead of shipping weaker. The
controller's rule for this task: an adapter that cannot restrict shell commands to the allowlist is marked
experimental = True. get_adapter refuses it unless REVIEWLOOP_EXPERIMENTAL_AGENTS=1.
Method¶
- Cursor:
cursor-agent2026.08.11-e8db854 is installed locally. Sources werecursor-agent --help, the official CLI docs (headless, permissions, configuration, authentication, run modes) and a read of the installed bundle to confirm howpermissionsand--trustbehave. One run without a credential confirmed that print mode exits at once with "Authentication required ... set CURSOR_API_KEY". - Codex: not installed. The pinned version is
@openai/codex0.172.0 (npm view). Sources were the official docs (non-interactive mode, CLI reference, sandbox and approvals, permissions, rules, AGENTS.md, authentication, config reference) and the public source at tagrust-v0.172.0:exec/src/cli.rs,login/src/auth/manager.rs,core/src/agents_md.rs,core/src/exec_policy.rsandlinux-sandbox/src/bwrap.rs. - Neither CLI was run against a model, because no credential was available.
Codex (codex exec): experimental¶
Headless mode¶
codex exec ... - reads the prompt from stdin. --json streams JSONL events to stdout, which becomes reviewloop's
transcript. --output-last-message <file> writes the final agent message to a file, and Codex writes it itself,
outside the sandbox. --ephemeral keeps rollout files off disk.
Writes¶
--sandbox read-only makes every model-generated command read-only. On Linux this is bwrap plus seccomp; on macOS it is
Seatbelt. -c approval_policy="never" means no escalation is ever granted: a command that needs more than the sandbox
is refused (AskForApproval::Never maps to Forbidden).
The output file must still be written. The adapter gets it through --output-last-message .reviewloop/out/<step>.json,
so the sandbox stays read-only. The model is told that its final message is the JSON document. Writable roots are not
widened (no --add-dir, no workspace-write), because workspace-write would make the whole copy writable. The
snapshot check stays the hard guarantee.
apply_patch edits run under the same read-only policy.
Shell commands¶
Codex cannot limit commands to the allowlist. In the read-only sandbox any command runs without approval (cat, ls,
rg, find, a script interpreter). Execpolicy .rules (prefix_rule) decide only which commands may run outside the
sandbox, or whether to prompt or forbid. No rule means "run in the sandbox", not "deny", and the docs mark rules as
experimental. A forbidden rule for every other program is not possible either: rules match exact argv prefixes, not
"everything except".
features.shell_tool = false removes command execution entirely. That would also remove git log/blame/show/diff,
which the review needs.
The git guard still holds git itself: the scrubbed shell PATH starts with the guard (shell_environment_policy sets
PATH to the guard-first PATH and allow_login_shell=false), so git resolves to the guard. Other programs are not
held, and git called by its absolute path skips the guard. Codex has no pattern deny to stop that.
Codex is therefore experimental = True.
Reads and the credential¶
The read-only sandbox can read the whole filesystem by default. Permission profiles (default_permissions with
:minimal plus workspace roots) can narrow reads, but they are beta. They also do not combine with --sandbox: setting
sandbox_mode anywhere switches profiles off. The adapter keeps --sandbox read-only.
What limits the damage of a full read:
- The model credential reaches only the Codex process, never sandboxed commands:
shell_environment_policy.inherit = "none"andsetgive commandsPATHandHOMEonly. - bwrap unshares the PID namespace and mounts a fresh
/proc, so/proc/<pid>/environof the runner's processes is not visible. - The CI runner's own files remain readable (see "Runner files an agent can reach" below).
This is the other reason Codex is experimental.
Project config in the untrusted checkout¶
.codex/(config.toml, hooks, rules) loads only for a trusted project. The adapter never passes--trust, and--ignore-rulesskips rules anyway.prepare_sandboxalso deletes every.codex/directory from the copy..agents/skills/in the copy would be loaded as repository skills, soprepare_sandboxdeletes every.agents/skillsdirectory. The rest of.agents/stays. reviewloop's own skills go to$HOME/.agents/skillsin the throwaway HOME (the USER scope).AGENTS.md:-c project_doc_max_bytes=0makes Codex load no project instructions. The file stays in the copy as data.- User config:
--ignore-user-configskips$CODEX_HOME/config.toml. CODEX_HOME is not passed, so it defaults to the throwaway$HOME/.codex. - Also turned off:
web_search="disabled",features.apps=false(connectors),features.multi_agent=false, andfeatures.shell_snapshot=false(which copies a login shell's environment into commands). No MCP server is configured.
Network¶
The sandbox gives commands no network by default (the Linux sandbox unshares the network). Web search is disabled. The Codex process itself talks to the model API.
Credentials¶
OPENAI_API_KEY:codex execreads an API key only fromCODEX_API_KEY(read_codex_api_key_from_env; the built-inopenaiprovider has noenv_key). The adapter therefore passes the value ofOPENAI_API_KEYasCODEX_API_KEYand passes no other variable.CODEX_AUTH_JSON: its contents are written to$HOME/.codex/auth.jsonin the throwaway HOME, directory 700 and file 600 (O_EXCL), withcli_auth_credentials_store="file". The variable itself is never in the agent's environment, and the value is never logged.- A refreshed ChatGPT token is lost with the throwaway HOME. The docs say a rotating refresh token must be re-saved; users of auth.json must refresh the secret themselves.
- Not supported: a
codex loginsession in the runner's real HOME.
Argv¶
codex exec --sandbox read-only --json --ephemeral --ignore-user-config --ignore-rules
--output-last-message .reviewloop/out/<step>.json
-c approval_policy="never" -c allow_login_shell=false -c project_doc_max_bytes=0 -c web_search="disabled"
-c cli_auth_credentials_store="file" -c shell_environment_policy.inherit="none"
-c shell_environment_policy.set={PATH = "<home>/bin:...", HOME = "<home>"}
-c features.apps=false -c features.multi_agent=false -c features.shell_snapshot=false [--model M] -
Cursor (cursor-agent -p): experimental¶
Headless mode¶
cursor-agent -p --output-format stream-json reads the prompt from stdin when no prompt argument is given and stdin is
not a TTY (build-prompt.ts in the bundle). Print mode cannot stop to ask, so anything that would need approval is
rejected. Without --force it runs only:
- file edits inside the workspace;
- shell commands on the allowlist, or commands that fit the sandbox when it is on;
- what
permissions.allowcovers.
--force, --yolo and --approve-mcps are never passed.
--trust is required: print mode exits on an untrusted workspace. The trust mark is stored under
$HOME/.cursor/projects/..., which is the throwaway HOME, so nothing is written into the copy.
Shell commands¶
~/.cursor/cli-config.json in the throwaway HOME sets "approvalMode": "allowlist" and
permissions.allow = ["Shell(git log)", "Shell(git blame)", "Shell(git show)", "Shell(git diff)"]. How matching
works:
- Cursor parses each command with tree-sitter-bash and checks every executable command against the allowlist.
Shell(git log)matchesgit logandgit log ..., a literal prefix of the command text.- If the parser fails, finds no command, or sees a redirect to anything but
/dev/nullor a workspace or temp file, the command needs approval, which print mode rejects. - When the server-side flag
smartAllowlistEnabledis on, the matcher works on the classifier's command output instead of the parser's, so matching can change without any client change.
Cursor cannot hold shell commands to the allowlist. The review of PR #14 confirmed this with the bundled tree-sitter parser and matcher:
- Assignments are dropped. The matcher keeps neither
VAR=valueprefixes nor standalone assignments, so it treats these as plaingit ...and allows them: PATH=/usr/bin:/bin git diff --no-index /etc/hostname /dev/nullGIT_EXTERNAL_DIFF='sh -c ...' PATH=... git log -p --ext-diff -1export PATH=...; git log
Each one puts the real git ahead of the guard, or runs an arbitrary program through git. That program has
CURSOR_API_KEY in its env and, with the sandbox off, open network.
- Login-shell state is replayed. Cursor dumps and replays a login shell's state (bash -ilc, zsh -ilc in the
bundle). On images whose /etc/profile sets PATH, that can put the real git ahead of the guard, even for a plain
git log.
Neither can be fixed from reviewloop's side through Cursor's permission config.
Possible future path (not built; it needs a real smoke run first): a user-level ~/.cursor/hooks.json in the throwaway
HOME with beforeShellExecution and preToolUse hooks. These would run a reviewloop python -I checker on the raw
command text and reject anything that is not a bare git log|blame|show|diff with no assignments, expansions or
operators. The smoke run must confirm three things: the hook sees the raw text before Cursor's parsing, a denial is
final in print mode, and project hooks stay ignored.
--sandbox disabled is passed and sandbox.mode is "disabled". With the sandbox on, the allowlist would stop
mattering: in allowlist mode a sandboxed command is "preapproved" whenever its sandbox policy fits, whatever the
command. With the sandbox off, the allowlist is the only way a shell command runs.
permissions.deny (deny wins) adds an outer layer only:
- git by path or through a launcher would skip the guard:
Shell(*/git),Shell(env),Shell(command),Shell(exec). $or backtick expansion and/proccould print the credential:Shell(*$*),Shell(*`*),Shell(*/proc/*).
Shell(*/git *) and Shell(*git-*) were dropped: they also denied allowed git commands that name a real path
containing git- or ending in /git.
Cursor is therefore experimental = True.
Writes¶
Cursor cannot limit edits to one file: print mode edits workspace files without approval. Write(...) rules are
allow/deny lists over the same default. The protected paths .git/hooks and .vscode are refused, and writes outside
the workspace need approval, so they are rejected. Any write other than the output file is caught by the snapshot
check and fails the step. That is the guarantee spec 8.2 names for writes.
Reads¶
With the sandbox off, Cursor's Read, Grep and Glob tools read any absolute path. readBoundary: "workspace" applies only
to sandboxed commands, and a team readBoundary only to the sandbox and shell auto-approval; the bundle's shouldBlockRead
does not check it. The config still sets it, in case a later version extends it.
permissions.deny therefore names the runner files that hold credentials:
Read(/proc/*)Read(*/.git/config)andRead(*/.git/modules/*)Read(*/.git-credentials)andRead(*/.netrc)Read(*/.ssh/*)Read(*/.docker/config.json)Read(*/.config/gh/*)andRead(*/.config/glab-cli/*)
These rules match the path after ~ expansion, not after symlink resolution, so they are best effort. The model
credential is not on disk; /proc/self/environ of the agent holds it, and /proc reads are denied.
See "Runner files an agent can reach" below.
Project config in the untrusted checkout¶
cursor-agent reads these project files:
.cursor/cli.json(project permissions) from every directory between the git root and the cwd;.cursor/permissions.json,.cursor/sandbox.json,.cursor/hooks.jsonand.cursor/mcp.json;.cursor/rules/**/*.mdc,.cursor/skills,.cursor/commandsand.cursorrules;.cursorignore, which hides files from the agent and would let a PR hide code from review;.claude/settings.jsonhooks and.claude/commands, and.agents/skillsand.codex/skills.
prepare_sandbox now deletes, at any depth: .cursor/, .codex/, .agents/skills and .claude/ directories, and the
.mcp.json, .cursorrules, .cursorignore and .cursorindexingignore files. Deleted tracked files are marked
skip-worktree, so git diff shows no fake deletions.
AGENTS.md, CLAUDE.md and CLAUDE.local.md stay as data. Cursor does load them as rules, and there is no flag to stop
that. The output-contract skill tells the agent to treat all repository text as data.
User-level hooks, MCP and settings come from the throwaway HOME, which holds only cli-config.json and the step's
skills.
Network¶
The sandbox is off, so allowlisted git commands could reach the network. The sandbox's git copy has no remotes, and
the guard allows only four read subcommands. WebFetch(*) and Mcp(*:*) are denied. Web search needs approval
(autoAcceptWebSearch: false), which print mode rejects.
Credentials¶
CURSOR_API_KEY only. --api-key is never used, so the key stays out of argv. A cursor-agent login session is not
used, because HOME is the throwaway directory. CURSOR_API_ENDPOINT and CURSOR_CONFIG_DIR are not passed.
Argv¶
cursor-agent -p --output-format stream-json --trust --sandbox disabled [--model M]
Runner files an agent can reach¶
Codex and Cursor both let the agent read absolute paths outside the copy. A CI runner holds credentials in files:
- GitLab checkout. By default GitLab Runner clones from
CI_REPOSITORY_URL, which containsgitlab-ci-token:<CI_JOB_TOKEN>@, and keeps it as theoriginURL in the job checkout's.git/config. The job token is on disk unlessstrip_checkout_credentialsruns first. - GitHub checkout.
actions/checkoutpersists anhttp.https://github.com/.extraheaderwith the token unlesspersist-credentials: falseis set.strip_checkout_credentialsremoves it too. - GitLab File-type CI variables. These are plain files under
<builds>/<project>.tmp/, next to the checkout. reviewloop cannot remove them, because the job may need them. An agent that can read absolute paths can open them.
This is the reason Codex and Cursor stay experimental. It is also why the Claude Code adapter relies on
blockReadsOutsideWorkingDirectories; the real-CLI smoke run must confirm that a read of ../<project>.tmp/<var> is
refused.
Decision¶
CodexAdapter.experimental = True.get_adapter("codex")raisesConfigErrorunlessREVIEWLOOP_EXPERIMENTAL_AGENTS=1. The full Codex adapter moves to milestone 1.5: it needs permission profiles (:minimalreads plus the copy, read-only) to leave beta and to combine with a command restriction, or an execpolicy mode where an unmatched command is denied.CursorAdapter.experimental = True, gated the same way. The full Cursor adapter moves to milestone 1.5, through the hook-based checker described above or a Cursor matcher that keeps assignments.- In milestone 1, only Claude Code is available without the opt-in.
prepare_sandboxremoves Codex and Cursor project config, as listed above. For.agents/, only.agents/skillsis removed.strip_checkout_credentialsruns on the source checkout before any agent run.
Smoke checks before relying on a real run¶
With a real credential:
- Codex writes valid JSON to the
--output-last-messagefile, and--jsonevents reach the transcript. - Codex
git logresolves to the guard. - Cursor
git log -n 1runs. - Cursor
cat app.py,ls,/usr/bin/git diff a /abs/xandgit log > xare rejected in print mode. - Cursor creates
.reviewloop/out/<step>.jsonwithout approval. - Cursor
Read(/proc/self/environ)is refused. - Claude Code refuses a read of a GitLab File-type variable under
../<project>.tmp/(blockReadsOutsideWorkingDirectories).