Trying OpenCode with Docker Sandboxes
I’ve been using OpenCode, but I tried it after hearing about an application that allows running OpenCode and Codex in a sandbox environment via Docker.
Docker Sandboxes
This creates a very small virtual environment where you can run OpenCode and Codex.
It has an independent file system separate from your environment, and by default, all network connections are blocked, allowing only explicitly permitted destinations.
Although Docker is involved, it’s not a container. It’s a virtual environment with its own kernel, so it’s safe.
My environment is WSL (Ubuntu) on Windows.
I thought I might need to install it on Windows, but it worked normally after installing it in WSL.
Installation
Installing on WSL can be done using the Linux installation method.
curl -fsSL https://get.docker.com | sudo REPO_ONLY=1 sh
sudo apt-get install docker-sbx
Copying from the official source results in REPO_ONLY= 1 with a space between = and 1, which causes an error.
After fixing it, the installation completes.
Preparation
It didn’t work as is.
First, you need to add yourself to the kvm group.
sudo usermod -aG kvm [your username]
Restart WSL once.
Log out of WSL
$ exit
Stop WSL from PowerShell
wsl --shutdown
Log back into WSL
$ wsl
Check that you’re in the kvm group using the id command on WSL.
$ id
groups=...,1001(docker),XXX(kvm)
Network Permissions
In Docker Sandboxes, you must explicitly allow network destinations.
Since we’re using OpenCode, allow communication with the OpenCode API.
$ sbx policy allow network opencode.ai:443
Since I also use GPT-5.6 from OpenCode, allow that as well.
$ sbx policy allow network api.openai.com:443
GitHub is apparently allowed by default, but I’ll also allow APIs and such.
$ sbx policy allow network "github.com:22"
$ sbx policy allow network github.com:443
$ sbx policy allow network api.github.com:443
$ sbx policy allow network "*.githubusercontent.com:443"
$ sbx policy allow network raw.githubusercontent.com:443
$ sbx policy allow network objects.githubusercontent.com:443
$ sbx policy allow network "models.opencode.ai:443"
For Using GPT-5.6
Also complete OpenAI authentication.
$ sbx secret set openai --oauth
Log in to OpenAI in advance and open the displayed URL.
Start
The start command is as follows.
Note that CPU core count and memory allocation cannot be changed later, so it’s recommended to specify these during the initial launch.
(Default: all CPU cores, half the memory allocated)
$ sbx run --cpus 10 -m 20g opencode
Replace opencode with codex or ClaudeCode if you want to use those.
For subsequent launches, use the following:
sbx run opencode
Settings
Since I’m using OpenCode Go, set the API key.
This needs to be set again in the sandbox environment.
/connect
I’m using DeepSeekV4 Flash, but change to your preferred model (via /models) and test it.
Bonus: Debugging Method
If it doesn’t work, run the following to check the results.
$ sbx diagnose
The results will be displayed as follows.
sbx diagnose
─────────────────────────────────────────
Installation
✓ CLI binary — found
/usr/bin/sbx
✓ Binary version — v0.39.0
✓ Daemon — healthy
version v0.39.0
✓ Daemon diagnostics — collected (78761 bytes)
Platform
✓ Virtualization — supported
/dev/kvm is accessible
Storage
✓ Storage directories — all 1 paths present
✓ Directory permissions — all writable
✓ Disk space — 865.4GiB free
865.4GiB free of 1007GiB on the state directory's volume
Connection
✓ Version match — v0.39.0
✓ Socket — responsive
✓ SSH client config — not configured
✓ Authentication — authenticated
─────────────────────────────────────────
12 passed
If any items fail, that’s the cause. Resolve it by asking ChatGPT and it will work.
Updates
If you’re on Ubuntu including WSL, simply run:
sudo apt update
sudo apt install --only-upgrade docker-sbx
If you’re already running a specific project, delete the template and rebuild.
Use the following command to check the sandbox list:
$ sbx ls
Delete the one you want to update and reinstall:
$ sbx rm [sandbox name]
$ sbx run opencode
Global network policies remain even after deleting and recreating the sandbox, so you usually don’t need to reconfigure them.
Want to enter the sandbox shell and do various things
$ sbx exec -it [sandbox name] bash
Check the sandbox name with sbx ls. If you want to create an SSH key for GitHub, create it normally while inside and register it with GitHub.
Launch with Session Specified
$ sbx run opencode -- -s ses_xxxxxxxxxxxxxxxxxxxxxxxxxx
Comments