← Blog
OpenCodeSandboxesAI agents

OpenCode permissions, YOLO mode and Docker: run it safely

Yura Dubinin
Yura Dubinin

OpenCode permissions are rules in opencode.json that set each tool action to allow, ask or deny, and out of the box almost everything is allowed. On OpenCode 1.19.5 the default agent runs shell commands and edits files without a prompt; it asks before reading .env files and before touching paths outside the project. To get prompts, you add rules. To get real isolation, you need a container or a virtual machine, because a permission rule matches the text of a command and cannot see what the command does.

If you want no prompts and no risk to your own machine, run OpenCode in a disposable cloud VM. On Lizard (lizard.build), lizard sandbox create -t claude -s small --timeout 600000 starts a Firecracker microVM with Node.js 22 and git for 10 minutes, and npm install -g opencode-ai adds OpenCode to it. A Small sandbox costs $0.0162 an hour, billed per second (Lizard pricing, checked 15 November 2026).

Everything below was run on 15 November 2026 with OpenCode 1.19.5 (the opencode-ai npm package) and OpenCode 2.3.0 (@opencode/cli), using the opencode/big-pickle model that opencode models lists without any credential. The two versions use different config formats, so each example says which one it is for.

How do OpenCode permissions work?

OpenCode checks every tool call against an ordered list of rules, and the last rule that matches decides. Each rule ends in one of three effects, as the OpenCode permissions docs describe them: allow continues without prompting, deny blocks the operation, and ask waits for your decision.

The format depends on the version. OpenCode 1 groups rules by tool under a permission key. OpenCode 2 uses one permissions array, and renames bash to shell and task to subagent (migration guide, checked 15 November 2026). Version 2 still reads version 1 config files, according to the same guide.

Rules live in opencode.json or opencode.jsonc in the project root, in .opencode/ inside the project, or in ~/.config/opencode/ for every project.

The defaults are permissive in both versions. opencode debug agent build on 1.19.5 prints the resolved rules for the default agent, and with no config file they start with this:

{ "permission": "*", "action": "allow", "pattern": "*" }

After that come four exceptions: ask for doom_loop, for external_directory, and for reads of *.env and *.env.* (with *.env.example allowed). In our test, 1.19.5 with no config ran echo hello > a.txt and cat a.txt straight away.

OpenCode 2 drops one of those exceptions. Its docs say the default policy allows external_directory, and it did in our run: with no config, 2.3.0 wrote /tmp/outside2.txt from a project in /workspace/app2 without asking, where 1.19.5 requested permission for /tmp/*. To get the old behaviour back on version 2, add this rule:

{ "action": "external_directory", "resource": "*", "effect": "ask" }

When a rule resolves to ask, the interactive client offers three replies: allow once, allow always, or reject. The docs say "allow always" saves a project-scoped allow rule, and that a saved approval never overrides a configured deny.

How do you allow or deny specific commands?

Put a catch-all rule first and the exceptions after it, because the last match wins. This setup asks before any shell command, lets read-only git commands through, and blocks pushes.

OpenCode 2 (opencode.jsonc, the example from the official docs):

{
  "$schema": "https://opencode.ai/config.json",
  "permissions": [
    { "action": "shell", "resource": "*", "effect": "ask" },
    { "action": "shell", "resource": "git status *", "effect": "allow" },
    { "action": "shell", "resource": "git diff *", "effect": "allow" },
    { "action": "shell", "resource": "git push *", "effect": "deny" }
  ]
}

OpenCode 1 (opencode.json):

{
  "$schema": "https://opencode.ai/config.json",
  "permission": {
    "edit": "ask",
    "bash": {
      "*": "ask",
      "git status*": "allow",
      "git diff*": "allow",
      "git push*": "deny"
    }
  }
}

We gave both versions the same three commands through opencode run. git status --short ran. git push origin main was blocked; 1.19.5 answered "The user has specified a rule which prevents you from using this specific tool call" and 2.3.0 answered "Permission denied: shell". ls -la hit the ask rule, and what happened next depends on the client. In the interactive terminal you get a prompt. In a non-interactive run nobody can answer, so 1.19.5 printed permission requested: bash (ls -la); auto-rejecting and 2.3.0 returned "This non-interactive run cannot ask the user for permission, so the request was rejected."

In patterns, * matches any run of characters and ? matches one, per the docs. In version 2 a shell pattern that ends in * also matches the bare command, so git status * covers both git status and git status --short.

Rules can also be set per agent. In version 2 they go under agents.<id>.permissions and are appended after the global rules, so they win on a conflict. The docs give a read-only reviewer as the example; we did not run this one:

"agents": {
  "reviewer": {
    "description": "Review code without changing it",
    "mode": "subagent",
    "permissions": [
      { "action": "edit", "resource": "*", "effect": "deny" }
    ]
  }
}

Does OpenCode have a YOLO mode?

OpenCode has no setting called YOLO. The equivalent is the --auto flag, which the 1.19.5 help text describes as "auto-approve permissions that are not explicitly denied (dangerous!)". It works on opencode and on opencode run, in both 1.19.5 and 2.3.0:

opencode run --auto "run the tests and fix what fails"

With --auto, every ask becomes an allow and every deny still holds. We reran the three commands from the previous section with the flag: ls -la now ran, and git push origin main was still blocked in both versions.

Two things follow for unattended runs. First, the default config is already close to YOLO, since it allows shell and edits without --auto; the flag only matters for the few ask defaults and for rules you added. Second, ask is the wrong effect for anything you want stopped in a script or CI job. Without --auto it is rejected, with --auto it is approved, and either way nobody reviewed it. Use deny for what must never run.

If you come from Claude Code, --auto plays the role of --dangerously-skip-permissions, with the difference that OpenCode keeps enforcing deny rules.

Are OpenCode permissions a sandbox?

No. A permission rule compares the command text with a pattern, and the command then runs with your user's full access to files, processes and the network. The OpenCode docs say so in a warning: "shell runs with the host user's filesystem, process, and network authority. Directory inference from command text is best effort, so prefer a narrow shell allowlist instead of patterns intended to recognize every dangerous command."

We tested how far a deny rule goes. With rm * denied and other shell commands allowed, on both 1.19.5 and 2.3.0:

Command the agent ranResult
rm victim.txtBlocked
ls README.md && rm v4.txtBlocked (the scanner checks each part of a compound command)
python3 -c "import os; os.remove('victim.txt')"Ran, file deleted
sh -c 'rm victim2.txt'Ran, file deleted

The same gap applies to secrets. On 1.19.5 the read tool asked before opening .env, and cat .env through the shell printed the file with no prompt, because the default rule for shell is allow.

So a denylist stops the obvious form of a command and little else. An allowlist is stronger: deny shell by default and allow the few commands the task needs. Even then, an allowed command such as npm test runs whatever the repository's scripts contain. If the agent works on code you have not read, or runs with --auto, the boundary has to be outside OpenCode.

How do you run OpenCode in Docker?

Build a small image with OpenCode and git, run it as a non-root user, and mount only the project directory. This is the Dockerfile we built with Docker Engine 29.9.3:

FROM node:22-bookworm-slim

RUN apt-get update \
 && apt-get install -y --no-install-recommends ca-certificates git ripgrep \
 && rm -rf /var/lib/apt/lists/*

ARG OPENCODE_VERSION=1.19.5
RUN npm install -g opencode-ai@${OPENCODE_VERSION}

USER node
RUN mkdir -p /home/node/.local/share/opencode
WORKDIR /workspace
ENTRYPOINT ["opencode"]

Build it, then run a prompt against the current directory:

docker build -t opencode-box .

docker run --rm \
  --cap-drop ALL --security-opt no-new-privileges \
  -v "$PWD":/workspace \
  -v opencode-data:/home/node/.local/share/opencode \
  opencode-box run --auto -m opencode/big-pickle "add a test for the parser"

The first -v mounts your project at /workspace. The second is a named volume for OpenCode's data directory, so sessions outlive the container. In our run the agent reported uid=1000(node), the file it created appeared in the host project owned by uid 1000, and ls /home inside the container showed only node. A file we had placed in the host's /root could not be read from the container.

Two notes from the test:

  • The mounted directory must be writable by uid 1000. On Linux, if your own uid is different, change the owner of the project directory or the USER line.
  • For a paid provider, pass the key from your environment with -e ANTHROPIC_API_KEY (or the variable your provider uses), and add -it and drop the run … arguments for the interactive terminal. We ran only the non-interactive form with the credential-free model.

There is also an official image. The OpenCode docs say "Docker images use versioned tags, for example ghcr.io/anomalyco/opencode:2.0.0". We pulled :2.3.0 (411 MB) and :1.19.5 (332 MB). Both are Alpine images that run as root from /, with ripgrep and without git, node, bash or python3. A run with -v "$PWD":/workspace -w /workspace worked, and the file it wrote was owned by root on the host. That is the reason for building your own image.

Docker limits what the agent can reach, and it has limits of its own. The container shares your machine's kernel. The mounted project, including .git, is fully writable. Any key you pass in is readable by the agent, and the network is open; --network none cut it off in our test, but then a hosted model cannot be reached either. For a stronger local boundary, see Docker Sandboxes, which run agents in local microVMs.

How do you run OpenCode in a cloud sandbox?

Create a VM, install OpenCode, clone the repository into it, and run with --auto. These are the commands we ran with Lizard CLI 4.0.128:

lizard sandbox create -t claude -s small --timeout 600000
SB=<the id it prints>

lizard sandbox exec $SB -- npm install -g opencode-ai
lizard sandbox exec $SB -- git clone https://github.com/octocat/Hello-World /workspace/hello
lizard sandbox exec $SB -- sh -c 'cd /workspace/hello && opencode run --auto -m opencode/big-pickle "Summarize the README"'

lizard sandbox rm $SB

Lizard Sandboxes are Firecracker microVMs, each with its own kernel, so the agent has no path to your laptop's files, keys or processes. We reran these exact commands on 15 November 2026: the sandbox had Node.js v22.23.2 and git 2.39.5, npm installed OpenCode 1.19.5, and the agent read the README and answered "Hello World!". It sees only what you clone or copy in. -s small gives 2 vCPU, 4 GB RAM and a 20 GB disk at $0.0162 an hour; 10 minutes costs about $0.003. --timeout is in milliseconds, and without it a sandbox is deleted after 5 minutes.

The CLI help also lists an opencode template. On 15 November 2026 the API did not accept it yet ("Unknown sandbox template" in both regions), so the steps above use the claude template, which already has Node.js 22 and git.

To use your own provider key, write it to a file, copy it with lizard sandbox files put $SB opencode.env /root/opencode.env, and source it before opencode run. Run OpenCode in a sandbox covers credentials, the web UI and getting changes back as a patch.

You need Lizard Pro ($19 a month with $19 of usage included) or its 7-day trial, which requires a card and includes $5 of usage. On the trial, one Small sandbox runs at a time and every sandbox is deleted at most 1 hour after it starts; longer runs need a paid plan (limits).

The same approach works for other agents; see Claude Code sandbox.

Which setup should you use?

Permission rules onlyDocker containerCloud microVM (Lizard Sandboxes)
What limits the agentText patterns on tool callsContainer namespaces, your mountsA separate VM with its own kernel
Can reach your home directory and SSH keysYesOnly what you mountNo
KernelYour machine'sShared with your machineIts own
Safe to use --autoOnly on code you trustFor the mounted projectYes, for what you copied in
Runs after you close the laptopNoNoYes, until the timeout (1 hour at most on the trial)
Cost$0$0$0.0162 an hour for Small, paid from the $19 of usage in Lizard Pro
SetupOne config fileDockerfile and a run commandCLI, account and card

Permission rules are enough when you sit at the terminal and answer prompts on your own repository. Docker is the cheapest fix for --auto on a single project. A cloud microVM fits untrusted code, long unattended runs and, on a paid plan, several agents at once. It is the only one of the three that costs money.

FAQ

Where is the OpenCode permissions config file? In opencode.json or opencode.jsonc in the project root, in .opencode/ inside the project, or in ~/.config/opencode/ for all projects. OpenCode 1 reads the permission key and OpenCode 2 reads the permissions array.

How do I stop OpenCode asking for permission? Start it with --auto, which approves every request that no rule denies. With the default config OpenCode already runs shell commands and edits without asking, so prompts come mostly from ask rules you or your team added.

Does --auto override deny rules? No. In our tests on OpenCode 1.19.5 and 2.3.0, git push origin main stayed blocked under a deny rule with --auto set, while a command under an ask rule ran.

Can OpenCode read my .env file? The read tool asks first by default. The shell tool does not: in our test cat .env printed the file without a prompt. Keep real secrets out of any directory the agent can reach.

Is there an official OpenCode Docker image? Yes, ghcr.io/anomalyco/opencode with versioned tags. The :2.3.0 and :1.19.5 images we pulled run as root and do not include git, so a custom image with a non-root user is the safer base for a mounted project.

Is a Docker container enough to run OpenCode with --auto? It protects files you did not mount. It does not protect the mounted project, the keys you pass in, or the network, and it shares the host kernel. For code you do not trust, use a virtual machine.

Build with AI. Ship with Lizard

You don't need a platform team to go live. Your whole cloud, one CLI command away.

Start 7-day trial
Services
—
Add-ons
—
Deployments
—
Sandbox starts
—

We use cookies for essential site functionality and analytics. See our Cookie Policy.