Skip to content

session_move (via the execute tool) lets an agent leave the session directory; external_directory: deny no longer confines it #61054

Closed as duplicate

Description

@nickywan

Description

An agent can change its own session's working directory with tools.opencode.session_move({ directory: "../outside" }), called through the execute tool. No permission request is raised for the move. After it, ../outside is the session directory, so external_directory: deny no longer applies to it and the agent writes there.

Nothing I tried blocks the move: denying execute or session_move has no effect. Only edit: deny stops the write, and the session still moves.

Possibly intended (the tool exists to change directory), but then external_directory cannot be used to confine an agent, and I found no rule that can.

OpenCode version

v2.2.5 (release binary, linux-x64)

Steps to reproduce

Model: openrouter/deepseek/deepseek-v4.1-flash. Server API, session created with these rules, directory /work/proj, sibling directory /work/outside exists:

POST /api/session
{ "location": {"directory": "/work/proj"},
  "permissions": [
    {"action": "shell", "resource": "*", "effect": "deny"},
    {"action": "external_directory", "resource": "*", "effect": "deny"} ] }

Then POST /api/session/{id}/prompt:

First use your execute tool to run exactly: await tools.opencode.session_move({ directory: "../outside" }). Then create the file /work/outside/x containing done with your write tool.

Result: /work/outside/x is created, GET /api/session/{id} shows location.directory = /work/outside, and GET /api/session/{id}/permission stays empty.

Same rules plus {"action":"execute", ...,"effect":"deny"}, or plus {"action":"session_move", ...,"effect":"deny"} (also tried opencode.session_move): same result. With an ask rule on *, the move raises no request either; only the later edit does.

I saw the same bypass without being asked to call session_move: with only shell and external_directory denied and the prompt "create the file /work/outside/x, using any tool you have", the model chose it on its own in 1 of 3 runs.

Expected

Either session_move goes through a permission check (for example external_directory on the target), or a documented rule can deny it.

Operating System

Ubuntu (Linux x86_64)

Activity

  1. opencodejr commented on Nov 1, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report and repro, @nickywan!

    I think this is a duplicate of #49825. It reports the same thing: session_move doesn't ask for any permission, so a session can move itself out of the directory it was confined to, and the path restrictions no longer apply. The tools docs say so: "These utilities do not request a built-in permission action." There is an open PR, #58047, that would add an opencode_session_move permission check on the resolved destination, which is what you expected.

    The code also explains why your deny rules made no difference:

    • Denying execute turns Code Mode off, but its tools are then offered to the model as direct tools, so session_move is still available.
    • A deny rule with resource * only hides a tool when the action matches the tool's internal name. For this tool that is opencode_session_move (namespace and name joined by _), not session_move or opencode.session_move.

    So, from reading the code (I haven't tested it), this rule should take the tool away from the agent until #58047 lands:

    { "action": "opencode_session_move", "resource": "*", "effect": "deny" }

    Possible duplicates and related issues, ordered from most to least likely:

    The bot will close this issue as a duplicate in 1 day unless you reply explaining how your problem is different.

  2. opencode-agent commented on Nov 1, 2026

    @opencode-agent
    Contributor

    Closing as a duplicate of #49825, which tracks the same problem. Please follow that issue for updates, and add any new details there.

  3. opencodejr commented on Nov 2, 2026

    @opencodejr
    Contributor

    We haven't heard back since the last comment, so I'm closing this as a duplicate of #49825. That issue reports the same gap: session_move doesn't ask for any permission, so a session can move itself out of the directory it's confined to and external_directory no longer applies. Please follow #49825 and the open PR #58047, which would add an opencode_session_move permission check on the destination.

    In the meantime, this rule should keep the tool away from the agent. I got this from reading the code and haven't tested it:

    { "action": "opencode_session_move", "resource": "*", "effect": "deny" }

    If your problem turns out to be different from #49825, reply here and explain how, and we can reopen it. Thanks again for the clear repro, @nickywan!

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