No description
  • Shell 78.4%
  • Dockerfile 21.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-23 12:55:22 +01:00
opencode init 2026-11-23 12:49:19 +01:00
proxy init 2026-11-23 12:49:19 +01:00
.example.env init 2026-11-23 12:49:19 +01:00
.gitignore init 2026-11-23 12:49:19 +01:00
block_opencode_network.sh add iptables script to block container ip 2026-11-23 12:55:22 +01:00
docker-compose.yml init 2026-11-23 12:49:19 +01:00
Dockerfile init 2026-11-23 12:49:19 +01:00
README.md init 2026-11-23 12:49:19 +01:00
SKILL.md init 2026-11-23 12:49:19 +01:00
taskfile.yml init 2026-11-23 12:49:19 +01:00

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 opencode container has no auth.json mount, 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 at http://proxy:8080/... with a placeholder API key.
  • The proxy container (proxy/Caddyfile) is the only place the real key lives. It replaces the Authorization header 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

  1. Add a handle_path /<name>/* block to proxy/Caddyfile that injects the credential from {env.<NAME>_API_KEY}.
  2. Pass <NAME>_API_KEY to the proxy service in docker-compose.yml.
  3. Add the provider to opencode/opencode.jsonc with baseURL: http://proxy:8080/<name>/... and a placeholder apiKey.

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-ai npm package)