OpenCode in Docker
Run OpenCode in a container: EnvHaven's open-source image with OpenCode built in, a managed workspace with nothing to run, and the folders and keys a container of your own has to keep.
Updated November 23, 2026 · Checked against OpenCode 1.18.32 in EnvHaven v1.9.0
A container keeps whatever OpenCode does with full access away from your own files, which makes it the usual home for unattended runs. EnvHaven is built on that idea in two forms: a managed workspace, which is the container already running on a server of its own, and the open-source workspace image, which you run with Docker yourself.
A managed workspace: nothing to run
- Open your workspace in any browser. It is the EnvHaven container on its own always-on server, with an HTTPS address for what you build.
- Tap Launch, choose OpenCode and tap Sign in: it runs
opencode providers loginfor you in the terminal. For an API key, choose Set key instead and pasteANTHROPIC_API_KEY,OPENAI_API_KEY,GEMINI_API_KEYorGOOGLE_API_KEY; the workspace keeps it write-only. - Start it with one tap: signed in, OpenCode gets a green dot in the Launch menu and an icon in the workspace’s top bar. Support is built in (1.18.32), so there is nothing to install or update.
- Give it a task. The image sets
OPENCODE_PERMISSION={"*":"allow"}, so OpenCode never asks.
The EnvHaven image, on your own Docker
The workspace image is MIT-licensed and ships OpenCode 1.18.32 beside 16 other agents. Its home is /config, so one volume keeps every agent’s settings and sign-in when the container is replaced:
docker run -d \
--name envhaven \
-p 8443:8443 \
-p 2222:22 \
-e PASSWORD=password \
-e SUDO_PASSWORD=password \
-v envhaven-config:/config \
ghcr.io/envhaven/envhaven:latest
Open http://localhost:8443, run opencode in the terminal and sign in. The self-hosted guide covers SSH and Haven CLI against it.
What a container for OpenCode has to keep
OpenCode keeps its settings in ~/.config/opencode and ~/.local/share/opencode (source). Settings live in ~/.config/opencode; saved keys and sign-ins live under ~/.local/share/opencode.
In a container of your own, mount a volume at each of those paths so a rebuilt container stays signed in, or pass ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY or GOOGLE_API_KEY as an environment variable instead of signing in.
Full access inside the container
For one session:
opencode --auto
For every session, as an environment variable:
export OPENCODE_PERMISSION='{"*":"allow"}'
--auto auto-approves every permission that is not explicitly denied; its help marks it “dangerous!”. Deny rules still apply, and in 1.18 the default rules deny reading .env files.