Skip to content

feat: enforce the /sandbox toggle with bwrap and sandbox-exec - #45

Merged
A-x6 merged 5 commits into
devfrom
sandbox-exec
Jul 31, 2026
Merged

A-x6 merged 5 commits into
devfrom
sandbox-exec

Conversation

@A-x6

@A-x6 A-x6 commented Jul 30, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #44

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The TUI's /sandbox toggle sets metadata.sandbox: true on the session and shows a badge, but no execution path ever read the flag — commands still ran with full host authority. This adds the backend.

packages/core/src/sandbox.ts wraps a shell command in a filesystem sandbox:

  • Linux: bubblewrap with a read-only root and the worktree/temp roots re-bound read-write:
args: [
  "--ro-bind", "/", "/",
  "--dev-bind", "/dev", "/dev",
  "--proc", "/proc",
  // No --unshare-pid: remounting procfs in a new PID namespace fails inside
  // containers (CI, devcontainers), and this sandbox only isolates the filesystem.
  ...input.writable.flatMap((dir) => ["--bind-try", dir, dir]),
  "--die-with-parent",
  "--", input.shell, "-c", input.command,
]
  • macOS: sandbox-exec with an inline seatbelt profile — (allow default) + (deny file-write*) + (allow file-write* (subpath ...)) for the worktree, temp locations, and /dev.
  • Fail closed: Windows, or a missing wrapper binary, refuses to run with a clear "disable the sandbox with /sandbox" message instead of silently running unsandboxed.

Both spawn paths consult the flag by reading the session row's metadata JSON column (v1 and v2 sessions share SessionTable): the core bash tool swaps its ChildProcess for the wrapped argv, and the v1 shell tool passes a wrapped command into its runner. Scope is filesystem isolation only — network and process authority are unchanged, and the permission/approval flow is untouched.

How did you verify your code works?

  • Real bwrap run: touch /etc/blocked inside the wrapper fails with Read-only file system, worktree writes succeed, /proc works. Also discovered --unshare-pid breaks under nested containers, hence the comment above.
  • bun test ./test/sandbox.test.ts ./test/tool-bash.test.ts from packages/core/ — 16 pass, including a new integration test that inserts a session with metadata.sandbox: true and asserts the wrapped argv (with bwrap installed) or the fail-closed error (without).
  • bun test ./test/tool/shell.test.ts from packages/opencode/ — 23 pass.
  • tsgo --noEmit clean in both packages.

Screenshots / recordings

Not a UI change (the /sandbox UI already exists).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

View with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is enabled.

@vercel

vercel Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
bolt-cli-app Ready Ready Preview Jul 30, 2026 11:20pm

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@DevFlex-AI, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 32 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8a0906d4-d0c1-47e8-a0e4-eef61973a786

📥 Commits

Reviewing files that changed from the base of the PR and between 25b7fdf and 4ae0e82.

📒 Files selected for processing (6)
  • packages/core/src/sandbox.ts
  • packages/core/src/tool/bash.ts
  • packages/core/test/sandbox.test.ts
  • packages/core/test/tool-bash.test.ts
  • packages/opencode/src/tool/shell.ts
  • packages/opencode/test/tool/shell.test.ts

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

The following comment was made by an LLM, it may be inaccurate:

@A-x6
A-x6 merged commit 7a3f365 into dev Jul 31, 2026
17 checks passed

This branch was successfully deployed

1 active deployment
Preview — 4ae0e82b Deployed Jul 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/sandbox toggle has no execution backend: sandboxed sessions run commands unrestricted

1 participant