[experimental] Add macos bash commands sandboxing#21538
Draft
e-n-0 wants to merge 19 commits intoanomalyco:devfrom
Draft
[experimental] Add macos bash commands sandboxing#21538e-n-0 wants to merge 19 commits intoanomalyco:devfrom
e-n-0 wants to merge 19 commits intoanomalyco:devfrom
Conversation
Contributor
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate Found:
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue for this PR
Closes #2242
Type of change
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 throughsandbox-exec -p <profile> ....The core flow lives in
src/sandbox/spawn.ts,src/sandbox/policy.ts, andsrc/sandbox/preset.ts, with integration work insrc/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:
excluded_commands, and can ask forbash:unsandboxedbefore retrying outside the sandboxallow_unsandboxed_retryis enabled, OpenCode can ask for the separatebash:unsandboxedpermission and retry without the sandboxSummary
default,strict,network), modes (workspace-write,read-only), extra read/write/deny roots, workspace-relativeprotected_roots, andexcluded_commands.bash:unsandboxedpermission flow, updated permission UI handling, and docs/security updates across config, permissions, tools, and the sandbox threat model.Current limits
How did you verify your code works?
Automated tests:
bun test test/tool/bash-sandbox.test.ts test/session/prompt-sandbox.test.ts test/pty/pty-session.test.ts test/sandbox/*.test.tsfrompackages/opencode~/.ssh/secretare deniedread-onlymode blocks workspace writes but still allows/tmpexcluded_commandsare blocked before spawnbash:unsandboxedand succeeds when allowed# opencode:unsandboxedrequests run unsandboxed on the first attemptManual tests:
Screenshots / recordings
Checklist