Repository navigation
fix(sbx): pull --apply refuses .codex/, which can start MCP servers - #594
Conversation
The refuse-list holds an invariant its own comment states: each entry "makes this machine run a command or start a program the next time an agent, an editor, git or direnv starts here, outside the sandbox". `.codex/config.toml` declares MCP servers with an arbitrary `command` and `args` that Codex CLI launches on the laptop, so it belongs there, and did not. A patch creating `.codex/config.toml` was applied into the working tree. The file is typically untracked, so `git diff` after `pull --apply` would not show it, and the next `codex` run in the repository starts the named command locally — the escape the list blocks for `.mcp.json` and `opencode.json`. One `AGENT_DIRS` entry. A directory entry already matches at any depth and under the existing case and Unicode folding, so `.codex/config.toml`, `.CODEX/...` and a bare `.codex` file-or-link where the directory goes are all covered, as `.claude` is. Tests assert the per-path refusal (nothing applied, index untouched) and the matcher's neighbours: `.codexrc` and `docs/codex/x.md` stay allowed. Also names `.codex/` in the two places that enumerate the list for readers: the user guide's pull section and SBX0 §10.3. Codex is not configured by `sbx up` today; this holds whether or not it ever is (#593). Fixes #592 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Mariusz Sabath <[email protected]>
Review of #594. 1. AGENTS.override.md (the substantive one). #592 raised it and the first commit closed only the refuse-list half, without saying it was declining the other: PROMPT_FILES stayed ['claude.md','agents.md'], so a patch creating AGENTS.override.md was applied with no warning at all — and Codex reads that file in preference to AGENTS.md, so it silently replaces the instructions the next agent session reads. Added to PROMPT_FILES, which warns rather than refuses, as the other prompt files do (text, not an executable). The test fails without the change: `expected '' to match /AGENTS\.override\.md/`. 2. Re-wrapped the pull paragraph in the user guide. The first commit left a 29-column orphan line mid-paragraph where its neighbours run 88-97; the whole sentence is now wrapped to the file's width. Also names AGENTS.override.md in the warning sentence there and in SBX0 §10.3. 3. Added `.CODEX/config.toml` to the folded-variants list, so the Unicode case is as thick as `.HUSKY`'s. Folding is shared, so this is coverage, not a fix. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Mariusz Sabath <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
Adds .codex to AGENT_DIRS, so pull --apply refuses any patch that writes .codex/ (Codex CLI's project config.toml can declare MCP servers that it launches on the laptop). It also adds AGENTS.override.md to the warned-about prompt files. The change is small and correct. Matching at any depth, case/Unicode folding and the bare-name link case all come from the existing directory-entry path. The tests cover refusal, folding variants, the negatives (.codexrc, docs/codex/x.md) and the override warning. Both docs that enumerate the list (user-guide §3 and SBX0 §10.3) are updated.
Author: mrsabath (MEMBER — maintainer)
Areas reviewed: TypeScript (mocactl sbx push), tests, docs
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: passing (all 15 checks green)
One non-blocking suggestion inline.
| const AGENT_DIRS: Record<string, string> = { | ||
| '.claude': 'Claude Code settings, hooks and commands', | ||
| '.opencode': 'OpenCode configuration and plugins', | ||
| '.codex': 'Codex CLI configuration, which can start MCP servers', |
There was a problem hiding this comment.
suggestion (non-blocking): recent Codex CLI releases also discover repo-scoped skills under .agents/skills/ (a SKILL.md plus optional scripts the agent runs on the host), which is the Codex counterpart of .claude/skills/ that this list already refuses via .claude. If that applies to the Codex versions you target, consider adding .agents here (or tracking it alongside #593). Please verify against current Codex docs before acting on this.
Review of #594: @ingpaolodettori-dev asked whether Codex discovers repo-scoped skills under `.agents/skills/`, and to verify against the current CLI before acting. Verified against codex-cli 0.163.0, installed locally: - `codex features list` has `skill_search` stable/true and `skip_host_skill_discovery` as a flag, so host skill discovery is on by default. - The binary carries both path literals: `grep -a` finds `.agents/skills` and `.codex/skills`. So a skill is a SKILL.md plus scripts the agent runs on this machine, which is what `AGENT_DIRS` exists to refuse — the same reason `.claude/skills/` is already covered by `.claude`. `.codex/skills/` was covered by the `.codex` entry; a sibling `.agents/` was not: false .agents/skills/x/run.sh <- a script, applied true .codex/skills/x/SKILL.md true .claude/skills/x/SKILL.md One `AGENT_DIRS` entry, matching at any depth and under the existing folding as the others do. Tests cover `.agents/skills/x/SKILL.md` and `.../run.sh` (both fail without the entry: the patch applies instead of raising PushError), plus `.codex/skills/x/SKILL.md`, and the negatives `agents/skills/...` (no dot), `.agentsrc` and `docs/agents/x.md`. Also re-wrapped the pull paragraph in the user guide, which the longer list left with a 7-column orphan line, and named `.agents/` in SBX0 §10.3. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Mariusz Sabath <[email protected]>
|
@ingpaolodettori-dev good catch on Verified against the CLI itself rather than the docs, since you asked for that. Installed $ codex features list | grep -iE "skill"
skill_mcp_dependency_install stable true
skill_search stable true
skip_host_skill_discovery under development false
$ grep -a -o -E "\.agents/skills|\.codex/skills" <the codex binary> | sort -u
.agents/skills
.codex/skills
The gap was only the sibling: One Full run: 123/123 push tests, 169/169 agent-config/up, prettier and Two notes:
Unrelated to this PR, but relevant to #593: |
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Follow-up on 4692035. The .agents entry closes the Codex repo-skills gap, and the tests cover the positives (SKILL.md, run.sh, .codex/skills) and the neighbours (agents/, .agentsrc, docs/agents/). Nothing moca or sbx up writes into a workspace lives under .agents/ (the only uses are $HOME/.agents/skills), so legitimate pulls aren't newly refused. CI is green. One non-blocking follow-up idea inline.
| '.claude': 'Claude Code settings, hooks and commands', | ||
| '.opencode': 'OpenCode configuration and plugins', | ||
| '.codex': 'Codex CLI configuration, which can start MCP servers', | ||
| '.agents': "Codex CLI's repo skills, whose scripts it runs on this machine", |
There was a problem hiding this comment.
suggestion (non-blocking, follow-up is fine): by the same reasoning, Pi itself (pinned kagenti/pi 2c28be5) loads project-local .pi/extensions/ as code (extensions/loader.ts:579), plus .pi/skills, .pi/prompts and project settings (resource-loader.ts:750), behind its project-trust check (resource-loader.ts:337). If someone runs pi on their laptop in the repo, a pulled .pi/extensions/x.ts is the same escape .opencode/ is refused for. Consider adding '.pi' here, or open an issue if you'd rather rely on Pi's trust prompt.
Same reasoning as `.codex/` and `.agents/`, applied to Pi itself (review comment on #594). Pi loads project-local `.pi/extensions/` as code (`extensions/loader.ts:579`), plus `.pi/skills` and `.pi/prompts` (`resource-loader.ts:750`). A pulled `.pi/extensions/x.ts` is the escape `.opencode/` is refused for: the file is typically untracked, so `git diff` after `pull --apply` would not show it, and the next `pi` run in the repository loads it on the laptop. Pi's project-trust check (`resource-loader.ts:337`) gates this, but the refuse-list does not rely on another tool's prompt for the others either, and moca vendors Pi (`pi-fork`, `PI_PINNED_COMMIT.txt`), so a developer running `pi` in this repository is the expected case, not a hypothetical. The directory is `CONFIG_DIR_NAME`, which defaults to `.pi` and is set to `.pi` by the pinned fork's `piConfig.configDir`; a fork that renamed it would need a second entry. One `AGENT_DIRS` entry, as before. Tests assert the per-path refusal for `extensions/`, `skills/` and `prompts/`, the folded variants (`.PI/`, `.Pi/`) and the bare-name case, and that the neighbours stay allowed: `.pirc`, `pi/extensions/x.ts`, `docs/pi/x.md` and `pi-fork/src/index.ts` -- the last matters here, since over-matching would refuse legitimate pulls touching the vendored submodule. Also names `.pi/` in the two places that enumerate the list for readers, and re-wraps both paragraphs. Refs #592 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Mariusz Sabath <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Follow-up review at 651fc44.
The new commit 651fc44 applies our 4692035 suggestion: it adds .pi to AGENT_DIRS, so pull --apply now refuses project-local Pi extensions, skills and prompts, as well as .pi/settings.json and SYSTEM.md, because a dir entry matches everything under it. It uses the same any-depth matching and case/Unicode folding as the other entries. Tests cover .pi/extensions/x.ts, .pi/extensions/x/index.ts, .pi/skills/x/SKILL.md, .pi/prompts/x.md, the folded .PI/ and .Pi/, and a bare .pi. The negatives are .pirc, pi/extensions/x.ts, docs/pi/x.md and pi-fork/src/index.ts, so the vendored submodule isn't over-matched. Both docs that enumerate the list are updated and re-wrapped.
I checked for regressions. No tracked .pi path exists at 651fc44. The repo's other .pi uses are $HOME/.pi/agent, which pull never touches, and a harness loader-lockdown test that plants <cwd>/.pi/ in a temp dir. Pi keeps its sessions under the agent dir, not <cwd>, so a normal sandbox session doesn't produce .pi/ in the workspace and legitimate pulls aren't newly refused. If an agent does write <cwd>/.pi/…, the pull is refused whole, as designed for .claude/, and the user can save the patch with -o FILE.
Author: mrsabath (MEMBER — maintainer)
Areas reviewed: TypeScript (mocactl sbx push.ts), tests, docs (incremental 4692035..651fc44, +34/−14)
Agent/IDE config (.claude/.vscode): none (gate grep over the full PR diff vs main: no matches)
Commits: 4 commits, all signed-off: yes
CI status: passing (all 16 checks green at 651fc44); mergeable_state clean
The refuse-list holds an invariant its own comment states: each entry "makes
this machine run a command or start a program the next time an agent, an editor,
git or direnv starts here, outside the sandbox".
.codex/config.tomldeclaresMCP servers with an arbitrary
commandandargsthat Codex CLI launches on thelaptop, so it belongs there, and did not.
A patch creating
.codex/config.tomlwas applied into the working tree. The fileis typically untracked, so
git diffafterpull --applywould not show it, andthe next
codexrun in the repository starts the named command locally — theescape the list blocks for
.mcp.jsonandopencode.json.One
AGENT_DIRSentry. A directory entry already matches at any depth and underthe existing case and Unicode folding, so
.codex/config.toml,.CODEX/...and abare
.codexfile-or-link where the directory goes are all covered, as.claudeis. Tests assert the per-path refusal (nothing applied, index untouched) and the
matcher's neighbours:
.codexrcanddocs/codex/x.mdstay allowed.Also names
.codex/in the two places that enumerate the list for readers: theuser guide's pull section and SBX0 §10.3.
Codex is not configured by
sbx uptoday; this holds whether or not it ever is(#593).
Fixes #592
Assisted-By: Claude (Anthropic AI) [email protected]
Signed-off-by: Mariusz Sabath [email protected]