Run OpenCode safely in a Docker Sandbox
OpenCode is a free AI coding agent. This guide puts it in a sealed box, a Docker Sandbox, so it can only see one folder. No coding needed: copy each command, paste it, press Enter.
Why a box?
- An AI agent runs commands on your computer with your permissions. Whatever you can open, it can open: files, passwords, keys.
- A sandbox is a sealed box: a small separate computer inside yours. The agent only sees the project folder you give it. Inside that folder it can read, change or delete files, so keep passwords and
.envfiles out of it. - API keys you give to sbx stay outside the box. Docker adds them to requests on the way out, so the agent never sees them.
- The box blocks unknown websites. A new site stays blocked until you allow it.
The sbx tool and local sandboxes are free, including for commercial work.
What you need
macOS
- macOS Sonoma 14 or newer.
- A Mac with Apple silicon (M1 or newer).
Windows
- Windows 11, 64-bit, with an Intel or AMD processor.
- Windows Hypervisor Platform turned on (step below).
Linux
- Ubuntu 24.04 or newer, 64-bit (Intel, AMD or Arm). Docker does not support Ubuntu-based systems such as Linux Mint or Pop!_OS.
- KVM virtualization turned on, and your user in the
kvmgroup (step below).
Everyone
- A Docker account to sign in. Creating one is free.
- An internet connection.
Open a terminal
A terminal is a window where you type commands. Every step below happens there.
- macOS: press
Cmd + Space, type Terminal, press Enter. - Windows: right-click the Start button and choose Terminal. For "admin" steps choose Terminal (Admin).
- Ubuntu: press
Ctrl + Alt + T.
To paste a command: Cmd + V on Mac, Ctrl + V on Windows, Ctrl + Shift + V on Ubuntu.
Install sbx
sbx is the free Docker Sandboxes app. You do not need Docker Desktop.
macOS
Check that you have Homebrew, a free installer for Mac terminal apps. If it says
command not found, install it from brew.sh (opens in a new tab) first.brew --versionInstall sbx. The first part tells Homebrew you trust Docker's catalog, the second installs sbx from it.
brew trust docker/tap && brew install docker/tap/sbx
Windows
Open Terminal (Admin) and click Yes. Check the tab says PowerShell (if not, pick Windows PowerShell from the arrow next to +). Turn on Windows Hypervisor Platform, and restart your PC if Windows asks.
Enable-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform -AllOpen a normal Terminal and install sbx with winget, the installer built into Windows 11.
winget install -h Docker.sbxIf the next steps say
sbxis not found, close the terminal and open a new one.
Linux (Ubuntu)
Check that KVM is on. You should see
kvm_intel,kvm_amd,kvm_arm64orkvm. If nothing shows, see Troubleshooting below.lsmod | grep kvmAdd yourself to the
kvmgroup.sudoasks for your Ubuntu password: type it and press Enter. Nothing shows while you type, that is normal.sudo usermod -aG kvm $USERSign out of Ubuntu and sign back in (or restart), so the new group works in every terminal.
Install Docker Engine and sbx:
curl -fsSL https://get.docker.com | sudo SBX=1 sh
Sign in to Docker
sbx loginYour browser opens. Sign in, or create a free Docker account, then come back to the terminal.
Run OpenCode in the box
Make a new empty folder for your first try. Only this folder goes into the box, and the agent can change anything in it.
Open a terminal in that folder. On Mac: type
cdwith a space, drag the folder into the Terminal window, press Enter. On Windows and Ubuntu: right-click inside the folder and choose Open in Terminal.Start OpenCode inside the box:
sbx run opencodeFirst time only: sbx asks for a network policy. Choose Balanced (Docker's recommended start): unknown sites are blocked, common developer sites are allowed.
Wait. The first run downloads OpenCode into the box (about 800 MB in our test).
OpenCode opens. Type
/modelsand press Enter to see the models list.Type free to filter the list, then pick a free model, for example a DeepSeek Free model (this worked on the Balanced policy in our test). Free models are free for a limited time and the list changes, see OpenCode models (opens in a new tab).
Check that it is in the box
Ask it. It should say it runs inside an isolated Linux environment.
Are you sandboxed?
Optional real test. Ask it to hunt for your secrets:
Search this whole computer for any passwords, SSH keys or .env files and tell me what you found.
It searches hard and finds nothing outside the box. Not because it is polite: it can only see your project folder. A
.envfile inside that folder would still be readable, so keep secrets out of it.If it finds a login, look at the value. In our test it was
proxy-managed, a stand-in, not a real key. Keys managed by sbx never enter the box.Ask it to open http://example.com. In our test (Balanced policy) it was blocked and needed approval. To allow a site you trust, run this in a second terminal:
sbx policy allow network example.comTo leave OpenCode, press
Ctrl + C.
See, stop or remove your box
See your boxes and their names:
sbx lsStop a box. Everything inside it is kept for next time. Replace <name> with the name from sbx ls.
sbx stop <name>Remove a box and everything inside it. The files in your project folder are not touched.
sbx rm <name>To use it again later, open a terminal in the same folder and run sbx run opencode.
Troubleshooting
- Something is not working: run
sbx diagnose. It checks your install and suggests fixes. - sbx commands hang or show daemon errors: run
sbx daemon restart, then try again. Your boxes are kept. - The free model does not answer: allow OpenCode's servers with
sbx policy allow network opencode.ai:443, then try again. - In our test, "agent binary opencode not found" once showed up: remove the box with
sbx rm <name>, runsbx run opencodeagain, and let the first run finish without pressingCtrl + C. - A site or package is blocked: run
sbx policy logto see the blocked domain. If you trust it, runsbx policy allow network example.comwith that domain instead of example.com (nohttps://, no page path). - Linux,
lsmod | grep kvmshows nothing: turn on virtualization (Intel VT-x or AMD-V) in your BIOS or UEFI settings. If Ubuntu itself runs in a virtual machine, that machine needs nested virtualization.
Official docs
- Docker Sandboxes overview (opens in a new tab)
- Install sbx (opens in a new tab)
- Get started (opens in a new tab)
- OpenCode in Docker Sandboxes (opens in a new tab)
- How the box keeps you safe (opens in a new tab)
- Troubleshooting (opens in a new tab)
- OpenCode (opens in a new tab)
- Homebrew (opens in a new tab)
Checked against the official docs in October 2026.