Skip to content

tool.use policy cannot deny the execute (Code Mode) tool: execute:*, execute and * are all ignored, while shell:* and * do block shell #56349

Open

Description

@PabloLec

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).

  1. 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')
  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" }
  ]
}
  1. User config, passed through OPENCODE_CONFIG_CONTENT (agent build allows 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" } } }
}
  1. 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 shell but apparently not for execute, which may go through a different permission action than the one tool.use resources are matched against. I could not find which action name execute is 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

  1. opencode-agent commented on Oct 17, 2026

    @opencode-agent
    Contributor

    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.json and agent.build.permission {"*":"allow"}. Results:

    • tool.use deny on shell:* or *, model calls shell → error, Blocked by configuration policy
    • tool.use deny on execute:*, execute or *, model calls execute with return 1+1 → completed, output 2

    The script below reproduces all five cases.

    From the code, tool.use policies are only applied when a tool asks for permission. The Code Mode execute tool never does, and its availability depends only on the agent's permission rules, which is why an agent execute: deny works and a policy doesn't.

    Related: #54044, #47177, #54595 / #54976, #55232.

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Reproduces #56349: a `tool.use` deny policy blocks `shell` but not `execute` (Code Mode).
    # Needs root (writes /etc/opencode/opencode.json) — run in a throwaway container.
    # From source: BUN_OPTIONS="--conditions=browser --preload=<repo>/packages/tui/node_modules/@opentui/solid/scripts/preload.js" OC="bun <repo>/packages/cli/src/index.ts" bash repro.sh
    # OC overrides the opencode command (default: `opencode` from PATH).
    set -u
    OC=${OC:-opencode}
    W=$(mktemp -d)
    # Fake OpenAI-compatible provider (from the issue): forces one tool call, then answers text.
    cat > "$W/mock.mjs" <<'MOCK'
    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')
    MOCK
    export HOME=$W/home XDG_CONFIG_HOME=$W/cfg XDG_DATA_HOME=$W/data XDG_STATE_HOME=$W/state XDG_CACHE_HOME=$W/cache
    mkdir -p "$HOME" /etc/opencode
    export OPENCODE_CONFIG_CONTENT='{"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() { # resource tool args
      echo "{\"policies\":[{\"action\":\"tool.use\",\"resource\":\"$1\",\"effect\":\"deny\"}]}" > /etc/opencode/opencode.json
      node "$W/mock.mjs" 18766 "$2" "$3" & local pid=$!; sleep 0.5
      local d; d=$(mktemp -d); pushd "$d" >/dev/null
      local out; out=$($OC run --standalone --auto --model mock/m1 --agent build --format json "go" 2>&1)
      popd >/dev/null; kill $pid; wait $pid 2>/dev/null
      echo "=== policy deny tool.use '$1' | model calls $2 $3"
      echo "$out" | grep -o '"status":"[a-z]*"\|"output":"[^"]*"\|"error":"[^"]*"\|Blocked by configuration policy' | sort -u
    }
    run 'shell:*'   shell   '{"command":"echo hi"}'
    run '*'         shell   '{"command":"echo hi"}'
    run 'execute:*' execute '{"code":"return 1+1"}'
    run 'execute'   execute '{"code":"return 1+1"}'
    run '*'         execute '{"code":"return 1+1"}'
    rm -f /etc/opencode/opencode.json

    Run it: bash repro.sh

  2. Dante-dan commented on Oct 17, 2026

    @Dante-dan
    Contributor

    I’m working on enforcing the Code Mode execute deny policy before the runtime starts, including nested calls. I’ll preserve policy ordering and add regression coverage for execute:*, execute, and *.

  3. samvallad33 commented on Oct 20, 2026

    @samvallad33

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions