Table of Contents
- OpenCode has no built-in sandbox, and the maintainers say so
- Why permissions are not an OpenCode sandbox
- Option 1: OS-level wrappers (bubblewrap, sandbox-exec, firejail)
- Option 2: Docker or Podman on your machine
- Option 3: Cloud sandboxes built for agents
- The always-on OpenCode sandbox: Agent37
- Which OpenCode sandbox should you pick?
- OpenCode sandbox FAQ
- Does OpenCode have a built-in sandbox?
- Is opencode --auto safe to use?
- Can OpenCode run in Docker?
- How much does an always-on OpenCode sandbox cost?
OpenCode has no built-in sandbox, and the maintainers say so
sandbox key, no seatbelt, no bubblewrap, no Landlock. Compare that with the competition. Codex ships an OS-level sandbox (Seatbelt on macOS out of the box, bubblewrap on Linux, plus a native Windows mode; we covered the details in our Codex sandbox guide), and Claude Code added a native /sandbox mode (see every Claude Code sandbox option). In the OpenCode thread, commenters ask whether Anthropic's open source sandbox-runtime could be wired in, or Codex's sandbox ported over, and a collaborator replied they would look into it.Why permissions are not an OpenCode sandbox
allow, ask, or deny per tool in opencode.json, with pattern maps for bash commands where the last matching rule wins, so the catch-all goes first:{
"permission": {
"bash": {
"*": "ask",
"git *": "allow",
"rm *": "deny"
}
}
}allow. The read tool denies .env files by default, but nothing stops an allowed bash call from running cat .env or python3 -c "print(open('.env').read())". Deny patterns match command strings, not effects.opencode --auto and the agent approves every request that is not explicitly denied. That is exactly how people want to run long autonomous sessions, and exactly when a prompt-injected or hallucinating agent does the most damage. The fear users keep posting in that GitHub thread is concrete: an agent with bash and network access can POST your files anywhere.Option 1: OS-level wrappers (bubblewrap, sandbox-exec, firejail)
sandbox-exec on macOS or bubblewrap on Linux, with writes restricted to the project directory and /tmp, reads of sensitive paths like ~/.ssh denied, and network limited to an allowlist. Hacker News threads add firejail recipes for the same idea (incus comes up too, but that is image-based and closer to Option 2's container model).ask for anything destructive.Option 2: Docker or Podman on your machine
ghcr.io/anomalyco/opencode, and the pattern is simple: bind-mount only the one project you are working on, keep a named volume for OpenCode's state so you are not logging in every session, and run --auto knowing the blast radius is the container and that one directory, provided you also close egress.~/.local/share/opencode (where auth.json lives), plus ~/.config/opencode for global config, or the agent forgets who you are between runs. Second, exfiltration: a container with open egress can still ship your code anywhere, so an outbound firewall or allowlist matters more than most people's deny rules. Our opencode-docker repo packages this: the official image pinned, a non-root user, a compose file for the TUI, and an egress-firewalled autonomous mode.Option 3: Cloud sandboxes built for agents
opencode template. Daytona ships a plugin that runs each session in its own cloud sandbox and syncs results back as git branches. Modal publishes a worked example, Vercel a guide with a strict outbound allowlist, and Docker's new `sbx run opencode` launches the TUI in a microVM. Tensorlake takes a hybrid route: the model loop stays local and only the tool calls execute in a remote Firecracker microVM.Provider | Published rate, 2 vCPU / 4 GB | Always-on month (730 h) |
E2B | ~$0.166/hour | ~$121 |
Daytona | ~$0.166/hour | ~$121 |
Modal (Sandbox rates) | ~$0.238/hour | ~$174 |
Agent37 | metered by the minute | $4.76 |
The always-on OpenCode sandbox: Agent37
curl -X POST https://api.agent37.com/v1/instances \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{ "template": "agent37-opencode" }'agent37-opencode template comes with OpenCode installed and working out of the box on the managed model: no login, no account with a model provider, no keys. The first chat turn just runs, metered against your prepaid wallet. To pin a specific model instead, set OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY, or OPENROUTER_API_KEY as instance env and OpenCode registers that provider at boot, billing your key rather than your wallet. You get chat, code, files, and shell on a lean image, plus a web terminal and file browser one subdomain away from the instance URL, and files, sessions, and memory persist until you delete the instance.vm instance is a full Linux virtual machine with its own kernel and KVM hardware virtualization, which means Docker runs in it (the standard gVisor type cannot run a Docker daemon). VM compute meters at 2.5x the standard rate, from $11.36 a month for the entry shape.Which OpenCode sandbox should you pick?
- Interactive coding on repos you trust: stay local. Tight permission config plus the opencode-sandbox wrapper plugin.
- Autonomous `--auto` sessions on your laptop: Docker with a project-only mount and an egress firewall. Start from opencode-docker.
- Burst workloads, CI, parallel task fan-outs: a per-second cloud sandbox. E2B's template or Daytona's plugin are the fastest starts.
- A persistent agent that works while you sleep: an always-on hosted sandbox. Agent37 runs OpenCode behind gVisor for $4.76 a month, or in a full VM from $11.36 when the job needs Docker. (Curious when a full VM is actually worth it? See microVM vs container.)
OpenCode sandbox FAQ
Does OpenCode have a built-in sandbox?
Is opencode --auto safe to use?
--auto flag approves every permission request that is not explicitly denied, and deny patterns match command text, not behavior. In a sandbox with scoped files and controlled egress, --auto is how OpenCode is meant to shine. On a bare laptop it hands a fast-moving agent your whole machine.Can OpenCode run in Docker?
ghcr.io/anomalyco/opencode. Mount a single project directory, persist ~/.local/share/opencode in a volume so logins survive restarts, and restrict outbound network if the agent will run unattended.