GeezerVison is showing github.com — [FEATURE]: Better execution permissions and sandboxing · Issue #48411 · anomalyco/opencode
[FEATURE]: Better execution permissions and sandboxing #48411DescriptionFeature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
OpenCode's current execution controls could be improved in three areas:
1. Make permission mode easier to access
The current permission settings are relatively hidden.
It would be useful to show the active permission mode directly in the conversation UI and allow quick switching during a session.
2. Add sandboxed execution
OpenCode has permission controls such as allow, ask, and deny, but lacks a built-in sandbox comparable to a restricted execution environment.
A sandbox could limit filesystem, network, and process access even when an action is approved.
3. Add optional model-assisted approval
For ask mode, an optional reviewer model could evaluate requested actions and decide whether to:
- auto-approve
- ask the user
- deny
Ideally, the reviewer model could be configured separately from the main agent, so a small and inexpensive model can handle approval checks.
These three features would make OpenCode safer and more convenient for autonomous execution. Reacted by KurisuWataru, PrinceGarth, James58899, Mohamed Abbas Mohamed Elsayed, Aaron Friesen, David Alan Hjelle and Stirling Goetz Activitygithub-actions commented on Sep 11, 2026 This issue might be a duplicate of existing issues. Please check:
andrewarrow commented on Oct 8, 2026 opencodejr commented on Oct 28, 2026 Thanks for the detailed suggestions, @xiesl97! To sum up, you're asking for three things: show the active permission mode in the conversation and let you switch it quickly; a built-in sandbox that limits filesystem, network and process access even for approved actions; and an optional, separately configured reviewer model that can auto-approve, ask or deny requests in ask mode.
On the third one: the v2 plugin API has a permission.evaluate hook that lets a plugin change a permission request's effect (allow / ask / deny) and attach a message. That could be a starting point for a reviewer-model plugin in the meantime.
The maintainers will consider these. I couldn't search for existing issues just now, so this may be linked to related requests later.
benjaminfrombe commented on Nov 15, 2026 Part 2 of this request is the main reason my team cannot move off Codex: without OS-level sandboxing we cannot give an agent unattended write access with any confidence, which is exactly what Codex's workspace-write + restricted network mode buys us today.
There are now two implementation attempts on the table:
- feat(core): add opt-in OS-level shell sandbox #63599 hand-rolls bubblewrap and Seatbelt profiles. No Windows backend, and the macOS profile is only string-tested.
- feat(core): sandbox agent shell commands with MXC #64093 (draft) builds the feature on Microsoft MXC instead: one engine for all three platforms (Seatbelt, bubblewrap, ProcessContainer), fail-closed when the backend cannot enforce the policy, and a separate
shell_unsandboxed permission so approving a sandboxed command never approves escaping it. It is verified against real backends on macOS, Linux (Debian 13 + bwrap 0.12) and Windows 11, including the platform gaps that are documented in the PR.
The design question for maintainers, before either attempt is worth polishing further: is opencode open to taking @microsoft/mxc-sdk as a dependency at all? It is the only maintained engine covering all three desktop platforms, but it currently costs about 118 MB unpacked per install (per-platform packages are being requested upstream: microsoft/mxc#1781), and MXC release builds on Windows emit required Microsoft diagnostic telemetry. If that trade-off is acceptable, #64093 is ready for design review. If it is not, the hand-rolled route of #63599 is the fallback and it would help to know which direction you prefer.
One more upstream limitation worth knowing during the review: MXC's process streams do not deliver under Bun yet (microsoft/mxc#1782), so sandboxed commands return captured output rather than streaming, which is also listed in the PR. supernecronomicon commented on Nov 15, 2026 +1 to point 2. One useful requirement is to keep provider credentials accessible to OpenCode while making them inaccessible to model-controlled tools.
In a synthetic Linux probe, we tested OpenCode 1.18.30 inside Anthropic's srt 1.0.0 with our test configuration, using a fake credential in OPENCODE_AUTH_CONTENT. The child command did not inherit that variable, but it could recover the fake credential from its parent's /proc/<pid>/environ. So clearing the child environment was insufficient in that setup.
A tool-level sandbox seems useful here: OpenCode handles authentication, while model-controlled commands run with restricted filesystem, network, and process access. The boundary also needs to protect credential stores, including files or databases, rather than relying on a clean command environment alone. Model-controlled file-reading tools need equivalent protection.
Regression checks should confirm that OpenCode can still authenticate while model-controlled tools cannot recover a fake provider credential through credential stores, ancestor process interfaces, or inherited descriptors. Reacted by Matijs van Zuijlen benjaminfrombe commented on Nov 16, 2026 @supernecronomicon - that requirement is exactly what we built into a standalone plugin in the meantime, no core changes needed: universal-opencode-sandbox (on npm, currently 0.4.1).
What it covers today:
- Agent shell commands (and optionally user
! commands and plugin shells) run in MXC sandboxes (Seatbelt / bubblewrap / ProcessContainer), fail-closed.
- Credential stores are read-denied at the filesystem level by default -
~/.ssh, ~/.aws, ~/.gnupg, ~/.kube, provider auth.json files (~/.local/share/opencode/auth.json, ~/.codex/auth.json, ~/.claude/.credentials.json), ~/.npmrc, docker and gh configs - independent of the command environment. OpenCode itself keeps full access because only the spawned command is contained.
- Escapes are a separate permission (
shell_unsandboxed) that names the exact command and asks the user. (Can be disabled in config)
What it does not cover yet, matching your regression list:
- Model-controlled file-reading tools (
read/grep/glob) run outside the shell sandbox, so they need equivalent protection in a core implementation - a fair requirement for feat(core): sandbox agent shell commands with MXC #64093.
- We have not explicitly tested the
/proc/<pid>/environ ancestor vector under MXC yet; your probe is a good regression case to adopt.
The plugin reads its policy only from user-owned config outside the workspace, so a repository cannot loosen it. brenoluz commented on Nov 19, 2026 Systematic verification on v2.0.24 (most prior reports in this thread were V1 — this is the "2.0" follow-up that the V1-era closures asked for):
What we ran (a live enforcement matrix, via the HTTP API):
external_directory: deny → the read tool was correctly denied ✓ — but the agent pivoted to bash: cat /tmp/... and executed, the content entered the model context (the gap reproduces on 2.0)
- The v2 array syntax genuinely works:
{action: "shell", resource: "cat /tmp/*", effect: "deny"} denied pre-execution (zero bytes executed — the scanner machinery is solid ✓), and last-match-wins behaved exactly as documented ✓
- But the pattern deny is trivially bypassable — 4/4 executed:
cat /tm""p/… (quote-splitting) · cat $HOME/../../tmp/… (expansion) · head < /tmp/… (redirection) · python3 -c 'open("…")' — and an exact-command deny was broken by merely adding a flag (cat file -n executed)
A migration gotcha we hit: V1 permission: {bash: {...}} does not map to v2 (permissions array, the shell action) — users following pre-2.0 guides silently have no shell rules. Worth a docs/migration warning. jhmaster2000 commented on Nov 21, 2026 I want to bring up here the fact that all of these existing PR attempts only account for sandboxing the shell tool, which is completely insufficient for proper full isolation/sandboxing of an agent's capabilities, and is still not even close to as secure or feature-complete as Codex's default sandboxed setup, which is what I and many others around this push for OpenCode sandboxing are looking for, a sandboxing experience at a bare minimum in parity with Codex.
I have created my own PR at #62292 to address this, covering the true full spectrum of tools available to the agent under the sandbox, just like an external sandboxing solution covering the entire OpenCode process would, the difference from those being the main OpenCode process is not sandboxed, which is a benefit, as it allows intentional user actions such as ! in-chat shell commands or user-approved network requests to still function on demand, and most importantly, agent-requested shell escape approvals for commands that are necessary to run outside the sandbox with reason, meanwhile a fully sandboxed OpenCode cannot provide those escapes when needed, which is why I also don't consider those a comparable or satisfactory solution.
Unfortunately that PR got closed for being too large, ironically, so I will now be trying to get it in by smaller chunks as requested by the bot, starting with #65168 #67011 (added Linux support now too), but I highly encourage anyone who is on macOS or Linux to try out #62292 if you're looking for a proper Codex-like and OpenCode-native agent sandboxing experience (you will need to pull and build it yourself of course), and provide any feedback on anything I might have missed still (and you can use it as your daily driver until upstream resolves this demand one way or another, I have personally being doing so and it works like a charm, and I intend to keep updating that PR somewhat-regularly until it or another proper sandboxing PR is merged, so it shouldn't fall out of date too much). john-okeefe commented on Nov 21, 2026 Adding a concrete use case from #65442 (closed as a duplicate of #53955): plan mode wrote and committed code while the UI showed plan mode, because the shell tool bypasses the edit-tool deny.
Proposal: per-agent write sandboxing at the OS level with a writable-path allowlist, the way Codex CLI does workspace-write with landlock/seccomp on Linux:
{
"agents": {
"plan": { "sandbox": { "writable": ["~/.opencode/plan", "$TMPDIR"] } }
}
}
Plan mode: the agent can run git log, grep, tests — anything — but writes outside the allowlist fail at the syscall no matter how the command is spelled (heredocs, redirects, tee, subshells, scripts). Build mode just adds the project tree to the allowlist.
Command-text permission matching can't do this job: you can't classify a command as read vs write from its text (git log > /etc/hosts, echo x | sudo tee file, subshells, pipes), so the enforcement has to live at the filesystem level. An interim command-text deny-list (redirects, tee, rm, sed -i, git commit) would catch honest accidents, but text matching is bypassable and the syscall-level version is the one that actually closes the gap. benjaminfrombe commented on Nov 21, 2026 @/tmp/opencode-comment.md benjaminfrombe commented on Nov 21, 2026 @/tmp/opencode-comment2.md hubick commented on Nov 24, 2026 If I attempt to sandbox an agent with a limited set of permissions in ~/.config/opencode/agents/<name>.md, and point that agent at a project folder where it is able to edit files, can the agent not just simply write .opencode/agents/<name>.md into that project folder with the same <name> (or that of any subagent it has access to invoke) and give itself a wider set of permissions via that? Am I missing something? Thanks. bmw commented on Nov 24, 2026
If I attempt to sandbox an agent with a limited set of permissions in ~/.config/opencode/agents/<name>.md, and point that agent at a project folder where it is able to edit files, can the agent not just simply write .opencode/agents/<name>.md into that project folder with the same <name> (or that of any subagent it has access to invoke) and give itself a wider set of permissions via that? Am I missing something? Thanks.
fwiw, i believe codex solves this by defaulting to .codex/ in the root of a project folder being read only. see https://github.com/openai/codex/blob/f22cc03b043e61a8bfd1f16880adcb19edc459c9/codex-rs/protocol/src/permissions.rs#L2395-L2438 hubick commented on Nov 24, 2026 OpenCode having a precedence model that allows projects to override the user settings seems like a bad security decision to me.
Personally, I don't think projects should be able to modify an agent defined elsewhere at all - but at the very least not widen permissions. I wish I could disable that.
Barring that, attempting to stop an agent from writing such instructions is interesting, but OpenCode lets you provide opencode.json throughout your entire project hierarchy, not just at the root, and both inside and outside of the .opencode/ folder.
"permissions": [
{"action": "edit", "resource": "opencode.json*", "effect": "deny"},
{"action": "edit", "resource": "*/opencode.json*", "effect": "deny"},
{"action": "edit", "resource": ".opencode/*", "effect": "deny"},
{"action": "edit", "resource": "*/.opencode/*", "effect": "deny"}
]
Does adding that to an agent fix this? tmccombs commented on Nov 25, 2026
OpenCode having a precedence model that allows projects to override the user settings seems like a bad security decision to me
Allowing it widen permissions is a problem. But I don't think there would be an issue with it narrowing permissions. That is, a project could deny access that is allowed by the global config, but it can't allow things that are denied globally. GenTang commented on Nov 25, 2026 Hi, I'm on the FinShield team at Finogeeks. We see an opportunity to make OpenCode more compelling for Windows users who want to let agents work on their everyday machines with an OS-enforced execution boundary.
OpenCode's security documentation currently states that agent execution is not sandboxed. FinShield adds an optional Windows AppContainer sandbox around the OpenCode Desktop V2 execution backend, complementing its existing permissions while keeping the Desktop workflow. We believe this could address a practical adoption concern and strengthen OpenCode's appeal to developers and teams on Windows.
Our Agent Safety Arena publishes Windows evaluations of Codex CLI, Claude Code CLI, DeepSeek Harness and WorkBuddy across four areas: privacy, desktop interaction, system integrity and data protection. It compares agents' built-in sandboxes with FinShield, with published test conditions, recordings and reviewed results.
Would maintainers be interested in a focused OpenCode evaluation covering normal development workflows, isolation coverage and denied operations? We'd like to agree on a supported integration path and a small compatibility test plan. The current plugin targets Windows x64, uses host networking, and has a product-licensed native engine.
Integration guide. Who would be the right maintainer to discuss this with?
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|