- Shell 78.4%
- Dockerfile 21.6%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| opencode | ||
| proxy | ||
| .example.env | ||
| .gitignore | ||
| block_opencode_network.sh | ||
| docker-compose.yml | ||
| Dockerfile | ||
| README.md | ||
| SKILL.md | ||
| taskfile.yml | ||
Codebox
Docker sandbox for running OpenCode with local or cloud inference, without exposing any API keys to the agent.
How secrets are kept away from the agent
.env / shell (host)
|
v OPENROUTER_API_KEY (proxy only)
+--------------------------------------------------------------+
| docker compose |
| |
| opencode --http--> proxy (Caddy) --https--> OpenRouter |
| (no keys) injects Bearer |
| \------http------> Ollama |
| (host) |
+--------------------------------------------------------------+
- The
opencodecontainer has noauth.jsonmount, no secret environment variables and no provider credentials baked into the image. Anything the agent can run inside the sandbox (env,cat ~/.local/share/opencode/auth.json,docker inspect, ...) reveals nothing. - Its provider config (
opencode/opencode.jsonc) points every provider athttp://proxy:8080/...with a placeholder API key. - The
proxycontainer (proxy/Caddyfile) is the only place the real key lives. It replaces theAuthorizationheader on the way to OpenRouter and forwards/ollama/*to Ollama on the host. Its admin API is disabled so nothing on the sandbox network can introspect it. - The agent can use the key (by making requests through the proxy) but can never read it.
Prerequisites
- Docker & Docker Compose
- Task (optional, for convenience commands)
Setup
cp .env.example .env
# edit .env and set OPENROUTER_API_KEY
task opencode-build
If you previously authenticated with /connect, the key is in
~/.local/share/opencode/auth.json under .openrouter.key.
Usage
Run tasks from the directory you want mounted as /workspace:
| Command | Description |
|---|---|
task opencode |
Run OpenCode in the sandbox (starts the proxy if needed) |
task opencode-shell |
Open a bash shell in the sandbox |
task opencode-build |
Build the sandbox image and pull the proxy image |
task opencode-stop |
Stop the proxy sidecar and remove the network |
task opencode-proxy-logs |
Tail proxy logs |
Switch between OpenRouter and Ollama models with /models inside OpenCode.
Configuration
All variables are read by Docker Compose on the host from .env (or the shell)
and are passed only to the proxy service, except WORKSPACE which is a
host-side mount path.
| Variable | Default | Description |
|---|---|---|
OPENROUTER_API_KEY |
(required) | Injected by the proxy as Authorization: Bearer ... |
OLLAMA_UPSTREAM |
http://host.docker.internal:11434 |
Where the proxy forwards Ollama traffic |
OPENCODE_MODEL |
anthropic/claude-sonnet-5.5 |
Default model for OpenCode |
OPENCODE_SMALL_MODEL |
anthropic/claude-haiku-4.5 |
Small model for lightweight tasks |
SANDBOX_INTERNAL |
false |
true cuts the sandbox off from the internet; only the proxy stays reachable (git/npm in the sandbox stop working) |
WORKSPACE |
. |
Host directory mounted to /workspace (set automatically by the tasks) |
Ollama models
Ollama models are now automatically discovered at container startup. The entrypoint script queries the Ollama API to find available models and their capabilities, generating a dynamic configuration that includes all compatible models with proper context lengths and tool support detection.
Adding another provider
- Add a
handle_path /<name>/*block toproxy/Caddyfilethat injects the credential from{env.<NAME>_API_KEY}. - Pass
<NAME>_API_KEYto theproxyservice indocker-compose.yml. - Add the provider to
opencode/opencode.jsoncwithbaseURL: http://proxy:8080/<name>/...and a placeholderapiKey.
Layout
Dockerfile sandbox image (Ubuntu 24.04, Node 22, opencode-ai)
docker-compose.yml opencode + proxy services, networks
proxy/Caddyfile credential-injecting reverse proxy
opencode/opencode.jsonc global OpenCode config mounted into the sandbox
.env.example template for proxy secrets
taskfile.yml convenience tasks
Environment
The sandbox image is based on Ubuntu 24.04 and includes:
- Node.js 22
- Git, curl, bash
- ripgrep, fd-find, jq
- OpenCode CLI (
opencode-ainpm package)