This has been a bug for a long time now.. at least 6 months ago I opened a bug on the github about it doing this. Was it the main agent or was it a sub agent?
OpenCode Plan Mode is just a prompt in the end, not a guarantee.
You have two options:
Fully sandbox your agent where no matter what it does it can't do much damage.
Use something like pi with pi-automode, where you have a second model (or the same model) double check every single tool call. So bad calls instantly get blocked and something that doesn't align with what you wanted (you said just write a plan, the main agent tries to edit files) usually gets blocked too. But it's just a layer of protection, no guarantee at all.
Because the one I made (see the link) has much more functionality that suits the workflow I use LLMs for. Esp. the ability for an LLM on one host to remote into another host - still sandboxed - makes trusting agents with typical sysadm tasks a lot easier. Another would be the sudoers-like ability to run tasks direcly on the host without opening up for anything but that very specific task.
Kinda. If you hard deny bash and all other shell access and only give it the read tool? Then it would be mostly safe.
As soon as you give it edit permissions then all bets are off (if the agent actually tries to do something malicious on your machine). For normal workflows blocking or always asking for bash would be pretty safe though.
Besides the whole point: An agent that can't use bash, Python scripts etc. won't be great at writing code.
Starting out with Claude Code and then OpenCode at work we always checked every single tool call (only giving "always" allowed to pure reads). But over time you read the calls less and less and just hit allow. So currently I like my setup more of a second model checking every call. Your main agent might start doing something stupid as it really wants to finish a task, the second model without the same context will block it.
Have you updated your opencode json to change the permission settings in plan mode? Because plan mode should have a guardrail that doesnât allow file edits.
If you have allowed file edits then itâs basically just a prompt that says donât edit which can obviously be violated. You might have also allowed file edits earlier in the conversation and made it apply to the entire conversation.
It does have a guardrail for edit tool or whatever it's called, but does not have one for shell by default. So it can escape pretty easily. I've seen it myself when in response to a theoretical question it started making a test project in /tmp to verify a hypothesis lol
It also cuts both ways - plan agent prompt is something like "you can't write anywhere except .opencode/plans and unless asked". Well, some models refuse to write plans even when asked (i think it was claude)
Fundamentally, as long as you want to allow shell access, you can't use plan mode to prevent edits. Agents can, and often will use the shell to write files. Sometimes without even trying the file edit tools first. The permission settings might catch some or even most attempts at editing files, but it's at best a statistical game.
Meanwhile, cutting off shell access prevents a ton of stuff you absolutely want your plan mode agents to be able to do.
Sandboxing plus good git hygiene is the right solution to this problem, and once you have a good sandbox, it's much more convenient to just turn off all the permissions and let the agent do whatever it wants.
The permissions system in opencode is just not worth engaging with.
Recommended: https://github.com/Dicklesworthstone/destructive_command_guard You just tell the agent to set it up for OpenCode. At least some protection from dangerous commands - the agents get blocked and start using âgit switchâ(backups) instead of âgit reset âhardâ and more temporary directories when they try to do ârm -rf $somePotentiallyEmptyVar/â and get rejected.
Revisa los permisos en el json. Puedes de negarle el uso de herramientas y te aseguras de esa forma que no toque nada que no debe. Siempre se deben revisar los permisos y su prompt.
Run OpenCode, MCP servers, formatters, plugins, and development tools together inside a container, with native language servers on OpenCode 1.x. Give the agent control of that environment while exposing only your selected project directory by default.
6
u/0xbyt3 25d ago
Which model? It can run command that isn't in its "disallow" list too. I am seeing opencode running "git commit" without an issue.
8
u/Asonagic 25d ago
DOES YOUR AGENT DEPLOY THINGS???
2
u/EvilGuy 25d ago
This has been a bug for a long time now.. at least 6 months ago I opened a bug on the github about it doing this. Was it the main agent or was it a sub agent?
56
u/Vlyn 25d ago
OpenCode Plan Mode is just a prompt in the end, not a guarantee.
You have two options:
7
u/Big_Day6767 25d ago
Have you updated your opencode json to change the permission settings in plan mode?
Because plan mode should have a guardrail that doesnât allow file edits.
If you have allowed file edits then itâs basically just a prompt that says donât edit which can obviously be violated. You might have also allowed file edits earlier in the conversation and made it apply to the entire conversation.
4
u/lilian_moraru 24d ago
Recommended: https://github.com/Dicklesworthstone/destructive_command_guard
You just tell the agent to set it up for OpenCode. At least some protection from dangerous commands - the agents get blocked and start using âgit switchâ(backups) instead of âgit reset âhardâ and more temporary directories when they try to do ârm -rf $somePotentiallyEmptyVar/â and get rejected.
2
u/CupZealous 25d ago
I use Hermes Agent with my OpenCode Go sub, the plan mode restricts tool calls
2
u/AveryFenix 21d ago
Mine keeps thinking its in plan mode and asking me to switch to build mode WHEN ITS IN BUILD MODE.
1
u/Mammoth_Ad_9619 25d ago
I haven't any issue with plan or build mode.
Nowadays I'm using omo slim plugin and it worked really great.
1
u/NEROisADRIO 25d ago
Sub agent can change things in open code
1
u/Roy197 24d ago
This has also happened to me in Claude code it's nothing new
1
u/ichisay 24d ago
Revisa los permisos en el json. Puedes de negarle el uso de herramientas y te aseguras de esa forma que no toque nada que no debe. Siempre se deben revisar los permisos y su prompt.
1
u/AlwaysHopelesslyLost 24d ago
Yep, welcome to the world of security. Turning complete makes anything possible, including bypassing any possible blacklist.
1
u/LeoVibeCoderz 20d ago
I has the same issue recently and asked the same questions.
0
u/Rude-Philosopher-69 25d ago
this is the main reason i created oc-box.
Run OpenCode, MCP servers, formatters, plugins, and development tools together inside a container, with native language servers on OpenCode 1.x. Give the agent control of that environment while exposing only your selected project directory by default.
enjoy!
https://github.com/groopcd/oc-box
-1
u/ZoldarAR 25d ago
What IDE / Coding App do you people use with OpenCode?
1
u/povlhp 25d ago
It says so clearly. Holes in the harness. Your fault