GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(opencode): add experimental macOS bash command sandboxing by e-n-0 · Pull Request #21538 · anomalyco/opencode

Conversation

@e-n-0

@e-n-0 e-n-0 commented Apr 8, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #2242

Type of change

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

What does this PR do?

This PR adds opt-in macOS command sandboxing with sandbox-exec.

When sandboxing is enabled, OpenCode now resolves experimental.sandbox, applies built-in or custom presets, builds a macOS Seatbelt profile, and launches covered command paths through sandbox-exec -p <profile> ....
The core flow lives in src/sandbox/spawn.ts, src/sandbox/policy.ts, and src/sandbox/preset.ts, with integration work in src/config/config.ts, src/tool/bash.ts, src/session/prompt.ts, src/pty/index.ts, and the related launch/runtime paths.

In practice, that changes command execution like this:

  • bash tool commands and session shell commands resolve sandbox settings before spawn, enforce excluded_commands, and can ask for bash:unsandboxed before retrying outside the sandbox
  • PTY sessions apply the sandbox only to the initial shell spawn
  • if a bash or session command hits a sandbox denial and allow_unsandboxed_retry is enabled, OpenCode can ask for the separate bash:unsandboxed permission and retry without the sandbox
  • the TUI and app permission prompts now surface the new sandbox-related permission flows, including reason-specific unsandboxed messaging

Summary

  • Adds the core macOS sandboxing pieces: preset resolution, policy generation, protected roots, config wiring, and the spawn wrapper that launches sandboxed processes.
  • Covers the main execution surfaces: bash tool commands, session command execution, PTY shell startup, and the related launch/runtime paths used by those flows.
  • Adds built-in presets (default, strict, network), modes (workspace-write, read-only), extra read/write/deny roots, workspace-relative protected_roots, and excluded_commands.
  • Adds the bash:unsandboxed permission flow, updated permission UI handling, and docs/security updates across config, permissions, tools, and the sandbox threat model.

Current limits

  • macOS only (does not cover Linux or Windows)
  • experimental and opt-in
  • does not sandbox MCP servers
  • does not intercept commands typed inside an already-running PTY session
  • PTY supports sandboxed initial spawn only; there is no unsandboxed retry path for PTY

How did you verify your code works?

Automated tests:

  • Ran bun test test/tool/bash-sandbox.test.ts test/session/prompt-sandbox.test.ts test/pty/pty-session.test.ts test/sandbox/*.test.ts from packages/opencode
  • 56 tests passed across the bash tool, session command, PTY, and sandbox policy/preset/spawn flows
  • The tests cover:
    • in-project writes still work in sandbox mode
    • PTY startup stays deterministic in sandbox mode
    • sensitive home reads like ~/.ssh/secret are denied
    • read-only mode blocks workspace writes but still allows /tmp
    • preset resolution and preset-driven permission defaults
    • excluded_commands are blocked before spawn
    • reactive unsandboxed retry asks for bash:unsandboxed and succeeds when allowed
    • proactive # opencode:unsandboxed requests run unsandboxed on the first attempt
    • rejected unsandboxed requests fall back to the sandbox and preserve the denial message
    • timeout, abort, and sandbox launch failure behavior still works through the sandbox wrapper

Manual tests:

  • Tried to run curl/wget commands in sandboxed environment with and without network enabled
  • Tried to force the model to ask elevated permission for a command
  • Tried to make the model understand that a command was failing because of the sandbox and then retry it without sandbox when allowed
  • Tested multiple sandbox configuration combinations with and without unsandboxed retry allowance
  • Tested during 2 weeks of intensive agentic workflows

Screenshots / recordings

Screenshot 2026-04-08 at 15 22 46

Checklist

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

reneleonhardt, rosner, and den1251 reacted with heart emoji
All reactions
  • ❤️ 3 reactions
@github-actions github-actions Bot added the needs:title label Apr 8, 2026
@github-actions

github-actions Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Hey! Your PR title [experimental] Add macos bash commands sandboxing doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

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

Potential Duplicate Found:

  • PR feat: configurable sandboxing for bash commands and local MCP servers on linux/macos #20316: "feat: configurable sandboxing for bash commands and local MCP servers on linux/macos"
    • feat: configurable sandboxing for bash commands and local MCP servers on linux/macos #20316

Why it's related: This PR also addresses command sandboxing functionality, specifically for bash commands and includes MCP server sandboxing on both Linux and macOS. The current PR (21538) is experimental macOS-only sandboxing, which may overlap with or be a refinement/alternative approach to PR #20316's broader sandboxing implementation.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@e-n-0
e-n-0 force-pushed the dev branch 3 times, most recently from bb776e0 to 3588063 Compare April 13, 2026 12:11
@e-n-0
e-n-0 force-pushed the dev branch from e9af97e to ce292a5 Compare April 16, 2026 10:01
@e-n-0 e-n-0 changed the title [experimental] Add macos bash commands sandboxing feat(opencode): add experimental macOS bash command sandboxing Apr 16, 2026
@github-actions github-actions Bot removed the needs:title label Apr 16, 2026
@e-n-0
e-n-0 marked this pull request as ready for review April 16, 2026 12:29
@e-n-0
e-n-0 requested a review from adamdotdevin as a code owner April 16, 2026 12:29
@opencode-agent
opencode-agent Bot force-pushed the dev branch from 2f2ed11 to 9f201d6 Compare April 16, 2026 21:55
e-n-0 added 18 commits April 20, 2026 12:59
@e-n-0
phase 1
21fbbe6
@e-n-0
docs: update SECURITY.md for macOS sandbox phase 2
fbdd85e
@e-n-0
phase 2
3b0c90a
@e-n-0
docs: update SECURITY.md for macOS sandbox phase 3
155aef6
@e-n-0
docs: document missing sandbox config knobs and no danger-full-access…
e909b8a
… mode
@e-n-0
docs: fix protected_roots and MCP exclusion wording in SECURITY.md
290fe86
@e-n-0
phase 3
b666bba
@e-n-0
some ui/ux fix - let the model know about rejection
3016852
@e-n-0
fix dev deps precommit
0299c66
@e-n-0
cleanup
a3f30b8
@e-n-0
remove sandbox lsp
73548e7
@e-n-0
add docs
d1254de
@e-n-0
doc and translation
2a171bd
@e-n-0
fix unsandboxed command allowing pattern
b473778
@e-n-0
fix rebase
6e89203
@e-n-0
fixes
9d3bc34
@e-n-0
remove useless
cbecd49
@e-n-0
fix test
70fa171
e-n-0 added 5 commits April 20, 2026 13:05
@e-n-0
rebase fix tests
7ea314c
@e-n-0
fix
813b69b
@e-n-0
more rebase fix
651ef97
@e-n-0
remove clutter
16344e5
@e-n-0
fix rebase
affc1c0
@e-n-0
e-n-0 force-pushed the dev branch from 503e992 to affc1c0 Compare April 20, 2026 11:45
@rekram1-node

rekram1-node commented May 15, 2026

Copy link
Copy Markdown
Member

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node rekram1-node closed this May 15, 2026
@rekram1-node rekram1-node added the automated-pr-cleanup label May 15, 2026
@80avin 80avin mentioned this pull request Jun 14, 2026
Is there a way to sandbox the agent ? #2242
Closed
@Dhirenderchoudhary Dhirenderchoudhary mentioned this pull request Aug 29, 2026
[Feature] OS sandbox for execute_bash Nano-Collective/nanocoder#1049
Closed
2 tasks done
@Bearmancer Bearmancer mentioned this pull request Oct 8, 2026
docs(opencode): document shell advisory gap for sandbox #53937
Closed
@jhmaster2000 jhmaster2000 mentioned this pull request Nov 6, 2026
feat: Add experimental full agent sandboxing on macOS #62292
Closed
4 of 6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adamdotdevin adamdotdevin Awaiting requested review from adamdotdevin

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

automated-pr-cleanup

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Is there a way to sandbox the agent ?

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@e-n-0 @rekram1-node
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.