Skip to content

fix(sbx): pull --apply refuses .codex/, which can start MCP servers - #594

Merged
mrsabath merged 4 commits into
mainfrom
fix/592-pull-refuse-codex
Oct 23, 2026
Merged

mrsabath merged 4 commits into
mainfrom
fix/592-pull-refuse-codex

Conversation

@mrsabath

Copy link
Copy Markdown
Member

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]

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]>
@mrsabath
mrsabath requested a review from pdettori as a code owner October 23, 2026 00:17
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]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 23, 2026

@ingpaolodettori-dev ingpaolodettori-dev 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.

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',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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]>
@mrsabath

Copy link
Copy Markdown
Member Author

@ingpaolodettori-dev good catch on .agents/skills/ — you were right, and it was a real hole. Addressed in 4692035.

Verified against the CLI itself rather than the docs, since you asked for that. Installed codex-cli 0.163.0 locally:

$ 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

skill_search is stable and on, skip_host_skill_discovery exists as an opt-out (so host discovery is the default), and the binary carries both path literals. A skill is a SKILL.md plus scripts the agent runs on this machine, which is exactly what AGENT_DIRS refuses — the same reason .claude/skills/ is already covered by .claude.

The gap was only the sibling: .codex/skills/ was already caught by the .codex entry from the first commit, .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 like the others. Both new tests fail without it — the patch applies instead of raising PushError — and pass with it. Negatives added so it cannot over-match: agents/skills/... (no dot), .agentsrc, docs/agents/x.md.

Full run: 123/123 push tests, 169/169 agent-config/up, prettier and tsc --noEmit clean, check-links 206 files / 0 broken.

Two notes:

Unrelated to this PR, but relevant to #593: .codex/config.toml turns out not to be read as project-local config in 0.163.0. codex doctor with cwd inside a repo holding a valid .codex/config.toml reports config.toml → ~/.codex/config.toml, MCP servers 0, and codex mcp add has no project-scope flag. So sbx up cannot wire Codex the way it wires Claude Code and OpenCode, and #593 needs rescoping — I will write that up there. It does not change this PR: refusing .codex/ and .agents/ is right either way, since a pulled patch can create those files whether or not up ever writes them.

@ingpaolodettori-dev ingpaolodettori-dev 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.

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",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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]>
@mrsabath
mrsabath merged commit c94ef27 into main Oct 23, 2026
15 checks passed
@mrsabath
mrsabath deleted the fix/592-pull-refuse-codex branch October 23, 2026 16:52

@ingpaolodettori-dev ingpaolodettori-dev 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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pull --apply does not refuse .codex/: a pulled patch can plant an MCP server that runs on the laptop

3 participants