Skip to content

fix(mocactl): sbx claude denies Claude Code's local tools (#702) - #703

Merged
esnible merged 2 commits into
rossoctl:mainfrom
esnible:fix/702-sbx-claude-deny-local-tools
Nov 9, 2026
Merged

esnible merged 2 commits into
rossoctl:mainfrom
esnible:fix/702-sbx-claude-deny-local-tools

Conversation

@esnible

@esnible esnible commented Nov 9, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #702. mocactl sbx claude left Claude Code's built-in tools (Bash, Read, Edit, Write, …) enabled, so the agent could act on the user's machine as well as the sandbox. --strict-mcp-config limits which MCP servers load, not the built-in tools. Only the permissions.deny list that sbx up writes into .claude/settings.json turned them off, so sbx claude was contained only when started inside a repo up had set up. With --sandbox ID from anywhere else, it wasn't contained.

  • claudeArgs() now passes --disallowed-tools with CLAUDE_DENY, the same list up writes. It's one comma-separated value placed before --strict-mcp-config, which ends the variadic flag, so a prompt after -- is never read as a tool name.
  • Cortex mode: in a repo sbx up --cortex set up, the deny is left out and the Cortex note up prints is shown, matching up and doctor. Cortex blocks local tools in sessions that have the sandbox's tools, and a Read deny would stop CLAUDE.md loading (sbx up's agent config: the CLAUDE.md steering never loads (Read deny), and stale deny names warn on every startup #568). Outside a repo, or with an unreadable .sbx/agent-config.json, the tools are denied.
  • "claude is not on PATH" fallback: it printed a claude command without the deny. It now prints the full command, quoted, so it can be copied.
  • Docs: corrected the claude.ts comment that called --strict-mcp-config "the same containment" as up, updated the sbx claude help text, and added notes in docs/sbx/user-guide.md.

One behavior change: with Read denied, plain sbx claude sessions no longer load the project's CLAUDE.md, the same trade-off sbx up makes. up --cortex is the way around it.

Testing

  • test/sbx-claude.test.ts has five new tests:
    • the full deny list, as one value before --strict-mcp-config;
    • outside a git repository;
    • in a repo up hasn't set up;
    • Cortex mode from a subdirectory;
    • an unreadable Cortex record.
      The existing assertions and the not-on-PATH fallback check the new flag too. 13/13 pass; against the old source, 9 of the 13 fail.
  • Typecheck, make lint and make check-links pass.
  • Full mocactl suite: 1691 passed, 5 failed. The failures are 4 TUI overlay tests and 1 sbx push test, all on 5 s timeouts and none in code this PR touches. Rerun on their own, all 5 files pass (216/216).
  • Not yet checked in a real Claude Code session: the flag is listed in claude --help for 2.1.306, but a run against a live sandbox hasn't confirmed local tools are refused.

Checklist

  • Commits are signed off (git commit -s).
  • make lint and the tests for the touched packages pass. The 5 full-suite timeouts above pass when rerun on their own.
  • Docs: changed behavior, flags or environment variables are reflected in the relevant README or
    docs/ page, with the right maturity label (see docs/CONTRIBUTING-DOCS.md).
  • Docs: make check-links passes if any Markdown changed.
  • A new spec or ADR is registered in docs/specs/README.md or docs/adrs/README.md. (N/A: no new spec or ADR.)

Assisted-By: Claude Code

`sbx claude` passed only --mcp-config and --strict-mcp-config. The
second limits which MCP servers load; it leaves Claude Code's built-in
tools (Bash, Read, Edit, Write, ...) enabled, and those act on the
user's machine. Only the permissions.deny list that `sbx up` writes into
.claude/settings.json turned them off, so `sbx claude` was contained
only when started in a repository `up` had set up. From anywhere else,
including `--sandbox ID` outside a repository, the agent could read,
write and run commands locally.

claudeArgs() now passes --disallowed-tools with CLAUDE_DENY, the same
list `up` writes, as one comma-separated value placed before
--strict-mcp-config, so a prompt in the caller's arguments is never
read as a tool name. In a repository `up --cortex` set up, the deny is
left out and the Cortex note is printed, as `up` does: Cortex blocks the
local tools in sessions with the sandbox's tools, and a Read deny would
stop CLAUDE.md loading. Outside a repository, or with a record that
cannot be read, the tools are denied.

The "claude is not on PATH" fallback now prints the full command,
deny included, so running it by hand does not undo the fix.

Fixes rossoctl#702

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Ed Snible <[email protected]>
@esnible
esnible requested a review from pdettori as a code owner November 9, 2026 20:06
@esnible esnible added the bug Something isn't working label Nov 9, 2026
@esnible esnible self-assigned this Nov 9, 2026
…soctl#703 review)

The test made its directory with mkdtempSync directly, which bypasses
the helpers' `made` list, so afterEach(cleanupTmp) never removed it and
each run left a sbx-not-a-repo-* directory behind. Export tmp() from
helpers/sbx.ts and use it, so cleanupTmp takes the directory back.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Ed Snible <[email protected]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 9, 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.

Approving. claudeArgs() now passes CLAUDE_DENY as one --disallowed-tools value ahead of --strict-mcp-config, so a trailing prompt can't be read as a tool name. That makes sbx claude contained from any directory, --sandbox ID outside a repository included, which closes #702. The not-on-PATH fallback now prints the full quoted command, and the Cortex exception matches up and doctor. The tests cover inside a repo, outside a repo, an un-up'd repo, Cortex from a subdirectory, and an unreadable record. CI is green except deploy-scripts-bash32, which was still pending when I drafted this.

One suggestion inline: dropping the deny relies only on the working-tree record .sbx/agent-config.json saying cortex: true. Nothing checks that Cortex is actually there.

Assisted-By: Claude Code

deps.claude ?? {},
values.sandbox,
values['control-plane-url'] !== undefined ? ctx.url : undefined,
await repoRoot(cwd).then(cortexMode, () => false),

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: Since #702, --disallowed-tools is the only thing keeping the agent off the laptop in a directory up didn't configure. This line switches it off whenever .sbx/agent-config.json in the work tree says cortex: true. up adds .sbx/ to info/exclude, but nothing stops a repository from committing that file. A clone carrying {"version":1,"cortex":true,"files":[],"dirs":[],"json":[],"markdown":[]} passes manifestProblem, so sbx claude --sandbox ID run there gets every local tool. It also prints the Cortex note, so the user thinks they're covered, even on a machine with no Cortex at all. up --cortex refuses in that case (agentopProblem, sync.ts:340), and doctor reports it (cortexCheck), but the launcher checks nothing. This is no worse than before the PR, but it's the one way left to get around the new flag. Two cheap options: (a) leave the deny in place unless .sbx/agent-config.json is untracked (git ls-files --error-unmatch fails); (b) only drop the deny when agentopProblem/mocaSandboxStatus say moca-sandbox is installed and loaded, and fall back to denying with a warning otherwise. (b) also covers a stopped Cortex service.

@esnible
esnible merged commit 1189402 into rossoctl:main Nov 9, 2026
17 checks passed
@esnible
esnible deleted the fix/702-sbx-claude-deny-local-tools branch November 9, 2026 22:14
@pdettori pdettori added this to the v0.11.0 milestone Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sbx claude does not deny Claude Code's local tools: the agent can act on the user's machine

3 participants