Repository navigation
Description
Description
A hard-deny policy { "action": "tool.use", "resource": "execute:*", "effect": "deny" } does not stop the Code Mode execute tool. The call runs and returns its result, including nested tool calls. The same policy shape works for shell, and * blocks shell but not execute.
Policies are described in the V2 migration documentation as the layer that outranks agent and project configuration, so a restriction that must hold is meant to be written as a policy. Code Mode is an escape hatch for every other restriction (nested tools, fetch, see also #54595, #47177, #54044), so being unable to deny it with a policy leaves no enforced way to turn it off other than a per-agent execute: deny permission, which a project config can widen.
This is not #54214 (the action name permission being dropped by the validator): tool.use is accepted and loaded, and it does block shell. It is also not #55232 (matching of raw strings for shell: and webfetch:): here no spelling of the resource matches execute.
Plugins
None
OpenCode version
2.0.31 (linux-x64 binary)
Steps to reproduce
Everything below is isolated (own HOME and XDG directories, a local fake OpenAI-compatible provider, no real model).
- Fake provider
mock.mjs. It answers every request with a forced tool call the first time tools are offered, then with text:
import { createServer } from 'node:http'
const [port, tool, argsJson] = process.argv.slice(2)
let called = false
createServer(async (req, res) => {
let raw = ''
for await (const chunk of req) raw += chunk
const body = JSON.parse(raw)
const offered = (body.tools ?? []).length > 0
const afterTool = body.messages.at(-1)?.role === 'tool'
const forceCall = offered && !afterTool && !called && (called = true)
const delta = forceCall
? { role: 'assistant', tool_calls: [{ index: 0, id: 'call_1', type: 'function', function: { name: tool, arguments: argsJson } }] }
: { role: 'assistant', content: 'done' }
const chunk = (choice, usage) =>
`data: ${JSON.stringify({ id: 'm', object: 'chat.completion.chunk', created: 1, model: body.model, choices: [{ index: 0, ...choice }], usage })}\n\n`
res.writeHead(200, { 'content-type': 'text/event-stream' })
res.write(chunk({ delta, finish_reason: null }))
res.write(chunk({ delta: {}, finish_reason: forceCall ? 'tool_calls' : 'stop' }, { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 }))
res.end('data: [DONE]\n\n')
}).listen(Number(port), '127.0.0.1')- Policy file, installed as
/etc/opencode/opencode.json(on Linux, in a throwaway mount namespace so the host is untouched:unshare --user --map-root-user --mount, then an overlay on/etc, then copy the file):
{
"policies": [
{ "action": "tool.use", "resource": "execute:*", "effect": "deny" }
]
}- User config, passed through
OPENCODE_CONFIG_CONTENT(agentbuildallows everything, so that only the policy stands in the way):
{
"providers": {
"mock": {
"package": "@opencode/ai/providers/openai-compatible",
"settings": { "baseURL": "http://127.0.0.1:18766/v1", "apiKey": "x" },
"models": { "m1": { "name": "m1", "limit": { "context": 100000, "output": 4000 } } }
}
},
"agent": { "build": { "permission": { "*": "allow" } } }
}- Run once per case from an empty directory:
node mock.mjs 18766 execute '{"code":"return 1+1"}' &
opencode run --standalone --auto --model mock/m1 --agent build --format json "go"and for the control:
node mock.mjs 18766 shell '{"command":"echo hi"}' &
opencode run --standalone --auto --model mock/m1 --agent build --format json "go"Observed (2.0.31)
Policy resource (action tool.use, effect deny) |
Tool called by the model | Result |
|---|---|---|
| none | execute return 1+1 |
completed, output 2 |
execute:* |
execute return 1+1 |
completed, output 2 |
execute |
execute return 1+1 |
completed, output 2 |
* |
execute return 1+1 |
completed, output 2 |
execute:return* |
execute return 1+1 |
completed |
execute:* and * |
execute return await tools.opencode.models({}) |
completed, nested tool output returned |
shell:* |
shell echo hi |
error, Blocked by configuration policy |
* |
shell echo hi |
error, Blocked by configuration policy |
Control: with the agent permission "execute": "deny" instead of a policy, the model gets No tool named "execute", so the permission layer does remove the tool. Only the policy layer does not.
Expected
tool.use on execute (execute:*, execute, or *) is blocked with Blocked by configuration policy, as it is for shell, and a denied execute cannot reach nested tools.
Notes
- The policy is evaluated for
shellbut apparently not forexecute, which may go through a different permission action than the onetool.useresources are matched against. I could not find which action nameexecuteis checked under. - I found nothing saying that Code Mode is out of the reach of policies, so the current behavior reads as a defect rather than a limit.
- Operating system: Linux x86_64. No plugin, no MCP server, no project config in the reproduction.
Operating System
Linux x86_64
Activity
opencode-agent commentedon Oct 17, 2026
Thanks for the detailed report. I reproduced this on 2.0.31, and it still happens on the latest
dev(22e771f), run from source.I used your isolated setup: the fake OpenAI-compatible provider, the policy in
/etc/opencode/opencode.jsonandagent.build.permission {"*":"allow"}. Results:tool.usedeny onshell:*or*, model callsshell→error,Blocked by configuration policytool.usedeny onexecute:*,executeor*, model callsexecutewithreturn 1+1→completed, output2The script below reproduces all five cases.
From the code,
tool.usepolicies are only applied when a tool asks for permission. The Code Modeexecutetool never does, and its availability depends only on the agent's permission rules, which is why an agentexecute: denyworks and a policy doesn't.Related: #54044, #47177, #54595 / #54976, #55232.
Reproduction script (repro.sh)
Run it:
bash repro.shDante-dan commentedon Oct 17, 2026
I’m working on enforcing the Code Mode
executedeny policy before the runtime starts, including nested calls. I’ll preserve policy ordering and add regression coverage forexecute:*,execute, and*.samvallad33 commentedon Oct 20, 2026
Hi Pablo,
Is Code Mode still getting past your execute deny policy, nested calls included?
I hit the same kind of problem where an agent kept running a command it had been allowed once. If that is what happened on your end, would you want to see something combining memory, authority, and security so a deny you wrote actually gets checked against every command before it runs?
If you want to throw it at that isolated repro, it is one line:
npx @vestige/init
It checks each command before it runs, keeps a deny you set from one session to the next, and writes a hash-chained receipt of every decision, so if anything does get through you can trace exactly what caused it.
Sam