Skip to content

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

Open
kyuz0 wants to merge 9 commits intoanomalyco:devfrom
kyuz0:sandboxing
Open

feat: configurable sandboxing for bash commands and local MCP servers on linux/macos#20316
kyuz0 wants to merge 9 commits intoanomalyco:devfrom
kyuz0:sandboxing

Conversation

@kyuz0
Copy link
Copy Markdown

@kyuz0 kyuz0 commented Mar 31, 2026

Issue for this PR

Closes none

Type of change

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

What does this PR do?

Adds bash sandboxing to OpenCode via Anthropic's Sandbox Runtime (srt). This executes agent commands in an isolated environment (bubblewrap on Linux, sandbox-exec on macOS).

The architecture is built around an abstract SandboxProvider interface so that other sandbox backends (like native bubblewrap, nsjail, or gVisor) can be easily implemented and selected in the configuration file in the future.

The sandbox is configured in opencode.json and supports:

  • Network Isolation: Blocks outbound requests except for explicit domains.
  • Environment Scrubbing: Clears process.env and injects only the env_whitelist.
  • Workspace Constraints: Restricts access to cwd and /tmp. Matches in deny_workspace_patterns are bind-mounted to /dev/null allowing neither read nor write access.
  • Binary Blocklisting: Prevents execution of binaries in deny_binaries.

Example Configuration (opencode.json):

{
  "$schema": "https://opencode.ai/config.json",
  "bash_sandbox": {
    "enabled": true,
    "provider": "srt",
    "domains": ["github.com", "registry.npmjs.org"],
    "env_whitelist": ["PATH", "HOME", "USER", "SHELL", "TERM"],
    "deny_workspace_patterns": [
      "**/*.env",
      "**/*.secret",
      "**/*_rsa"
    ],
    "deny_binaries": ["terraform", "aws", "docker"]
  }
}

How did you verify your code works?

Ran local tests (bun test test/sandbox/srt.test.ts) that check:

  • Unapproved network requests fail.
  • Environment variables are dropped.
  • Out-of-workspace reads (e.g. ~/.bash_history) fail.
  • Matches against .env block read, write, rm, and chmod syscalls, including files created dynamically by the agent.

Note for reviewers: I am not sure if the tests as written fit the repository's standard CI flow, as they require srt to be installed on the host machine to pass.

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

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

Donato Capitella added 2 commits March 31, 2026 16:25
@github-actions github-actions bot added needs:title needs:compliance This means the issue will auto-close after 2 hours. labels Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title Configurable sandboxing for Bash commands on linux/macos 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.

@kyuz0 kyuz0 changed the title Configurable sandboxing for Bash commands on linux/macos feat: configurable sandboxing for bash commands on linux/macos Mar 31, 2026
@github-actions github-actions bot removed needs:title needs:compliance This means the issue will auto-close after 2 hours. labels Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@kyuz0 kyuz0 changed the title feat: configurable sandboxing for bash commands on linux/macos feat: configurable sandboxing for bash commands and local MCP servers on linux/macos Apr 1, 2026
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.

1 participant