A minimal, hardening-first container runtime for OpenCode and Oh-My-Pi, the AI coding agents for your terminal, built on Chainguard Wolfi with a pinned digest, a non-root user, and an entrypoint that transparently adapts to bind-mounted repositories.
Running an AI coding agent directly on your machine gives it full access to your environment. This image gives the agent an isolated, ephemeral, minimal Linux userland instead, while still letting it work on your real repository through a bind mount, with files it creates owned by you on native Linux (not by a container uid).
The image and entrypoint are built to be safe by default (non-root, no
setuid binaries, no privilege-escalation path back to root). But containers
are not a full sandbox out of the box: capabilities, the network namespace,
and the root filesystem are only as locked down as the flags you pass to
docker run. See Hardening: keeping the agent scoped to
/workspace for the flags
that close that gap.
# Default: builds the pinned OpenCode release (see OPENCODE_VERSION in opencode/opencode.Dockerfile)
docker build -f opencode/opencode.Dockerfile -t agent-box-opencode:local .
# Pin a different OpenCode release (bump OPENCODE_VERSION and VERSION together
# so the installed binary and the OCI version label stay in sync)
docker build -f opencode/opencode.Dockerfile --build-arg OPENCODE_VERSION=<x.y.z> --build-arg VERSION=<x.y.z> -t agent-box-opencode:<x.y.z> .
# Pin a different version of a bundled tool (ripgrep, jq, yq, patch, diffutils)
docker build -f opencode/opencode.Dockerfile --build-arg JQ_VERSION=1.8.2-r1 -t agent-box-opencode:local .
# Pin a different shellcheck release. Also update SHELLCHECK_SHA256_AMD64 /
# SHELLCHECK_SHA256_ARM64 to that release's linux tarball checksums
# (sha256sum of each downloaded asset) or the build fails closed. The .tar.gz
# assets the Dockerfile expects exist only from v0.11.0; older tags publish
# .tar.xz only.
docker build -f opencode/opencode.Dockerfile --build-arg SHELLCHECK_VERSION=v0.11.0 \
--build-arg SHELLCHECK_SHA256_AMD64=<sha256> --build-arg SHELLCHECK_SHA256_ARM64=<sha256> .
# OCI revision metadata
docker build -f opencode/opencode.Dockerfile --build-arg REVISION="$(git rev-parse --short HEAD)" .Corporate networks that TLS-inspect traffic (Zscaler, Netskope, and similar)
break apk add/curl inside the build with certificate verify failed,
because the base image's trust store only has public root CAs and has never
seen your proxy's private root. Fix it for your build only, without baking
the CA into the shipped image, using a BuildKit secret:
docker build -f opencode/opencode.Dockerfile --secret id=external_ca,src=/path/to/your-ca-bundle.pem -t agent-box-opencode:local .- The secret is mounted into a tmpfs for that build step only; it is never written to an image layer, so it never ships in the image you push or share.
- Builds without
--secretare unaffected; the flag is opt-in. - Get your proxy's root CA from your OS trust store (e.g. macOS Keychain Access → System keychain → export the root certificate authority your security tooling installed) since it's already trusted there for your browser to work behind the same proxy.
On native Linux, if your host uid is not
10001, add--user "$(id -u):$(id -g)" --group-add 0so the agent can write its config/data dirs with no root involved; see On native Linux (file ownership).
cd your-project
docker run -it --rm \
--user "$(id -u):$(id -g)" --group-add 0 \
-v "$PWD:/workspace" \
-v "$HOME/.local/share/opencode:/home/agent-box/.local/share/opencode" \
agent-box-opencode:local--user "$(id -u):$(id -g)" --group-add 0(native Linux only) matches your host uid/gid exactly (files the agent creates come out owned by you) while adding gid 0 as an extra group so the pre-baked config/data dirs are writable. Omit this on macOS/Windows (Docker Desktop already squashes bind-mount ownership) or if your host uid happens to be10001.-v "$PWD:/workspace"mounts your repository, the agent's working directory-v "$HOME/.local/share/opencode:..."(optional) persists sessions/auth across containers so you don't re-login on every run
OpenCode reads its configuration from ~/.config/opencode/. You can inject
your own configuration, custom agents, and skills by mounting files or
directories from the host:
# Full config directory (opencode.json, agents/, skills/)
docker run -it --rm \
-v "$PWD:/workspace" \
-v "$HOME/.config/opencode:/home/agent-box/.config/opencode" \
agent-box-opencode:local
# Individual config file only
docker run -it --rm \
-v "$PWD:/workspace" \
-v "$HOME/.config/opencode/opencode.json:/home/agent-box/.config/opencode/opencode.json" \
agent-box-opencode:local
# Custom skills directory
docker run -it --rm \
-v "$PWD:/workspace" \
-v "$HOME/.config/opencode/skills:/home/agent-box/.config/opencode/skills" \
agent-box-opencode:localContainer paths:
| Host path | Container mount | Purpose |
|---|---|---|
~/.config/opencode/ |
/home/agent-box/.config/opencode/ |
Full config: opencode.json, agents, skills |
~/.config/opencode/opencode.json |
/home/agent-box/.config/opencode/opencode.json |
Main configuration file |
~/.config/opencode/agents/ |
/home/agent-box/.config/opencode/agents/ |
Custom agent definitions |
~/.config/opencode/skills/ |
/home/agent-box/.config/opencode/skills/ |
Custom skill definitions |
The entrypoint creates ~/.config/opencode on first run if it does not exist.
When you bind-mount a directory over it, the mount replaces the container
directory, and your host files are used as-is.
docker run -it --rm -v "$PWD:/workspace" agent-box-opencode:local run "explain this repo"
docker run --rm -v "$PWD:/workspace" agent-box-opencode:local --versionRun OpenCode as a headless HTTP server (no TUI). The image auto-binds the
server to 0.0.0.0 inside the container in serve mode so a published port
reaches it and you don't need to pass --hostname yourself. The server is the
agent's control plane: it can read/write everything under /workspace and
run shell commands, so publish it to loopback only and always set a password.
PW="$(openssl rand -hex 24)"
docker run --rm -d -p 127.0.0.1:4096:4096 -v "$PWD:/workspace" \
-e OPENCODE_SERVER_PASSWORD="$PW" \
--name opencode-server agent-box-opencode:local serve-p 127.0.0.1:4096:4096publishes the serve port to loopback only; omitting the127.0.0.1:prefix (or using-P, since the image also declaresEXPOSE 4096) publishes on all host interfaces, reachable by anyone on your LAN/VPN-e OPENCODE_SERVER_PASSWORD=...sets the password. V2 generates one and printsserver password <value>on startup when you do not set this variable, so the server is never left unauthenticated; setting it yourself keeps the password known and stable (see Authentication below)-druns it detached (long-running server)-v "$PWD:/workspace"mounts your repository (the server operates on it)
Check the server (V2 exposes server info, including the version, at
/api/info, behind HTTP basic auth):
curl -s -u "opencode:$PW" http://localhost:4096/api/info
# {"version":"...","pid":...,"urls":[...],"paths":{...}}OpenAPI 3.1 spec (generate clients / inspect types) and the bundled web UI:
curl -s -u "opencode:$PW" http://localhost:4096/openapi.json -o openapi.json
open http://localhost:4096/ # web UI; sign in with the passwordStop the server:
docker stop opencode-serverNote: V2 handles SIGTERM gracefully, so
docker stop opencode-servershuts the server down cleanly. The entrypoint execs opencode as PID 1 (directly, or viasetprivwhen adapting uid/gid with--user 0;setprivreplaces its own process image rather than forking, so opencode still ends up as PID 1), so signals reach it directly. With--rmthe container is removed once stopped.
| Flag | Description | Default |
|---|---|---|
--port |
Port to listen on | 4096 |
--hostname |
Hostname to bind (image defaults to 0.0.0.0 in serve mode) |
127.0.0.1* |
--cors |
Additional browser origins (repeatable) | [] |
* The upstream 127.0.0.1 default is loopback-only and unreachable from the
host through a published port; the image injects --hostname 0.0.0.0 when you
run serve without an explicit --hostname. Pass --hostname 127.0.0.1 to
restrict to loopback, or any other value to customize.
Override port and restrict to loopback inside the container too (only
reachable via docker exec, since a loopback-bound server is not reachable
through a published port at all):
PW="$(openssl rand -hex 24)"
docker run --rm -d -v "$PWD:/workspace" -e OPENCODE_SERVER_PASSWORD="$PW" --name oc-lb agent-box-opencode:local serve --port 4097 --hostname 127.0.0.1
docker exec oc-lb curl -s -u "opencode:$PW" http://localhost:4097/api/infoDo not reach for
--network hostto work around this instead: it removes the container's network namespace entirely, so every service listening on your host's loopback interface (databases, other dev servers, a TCP-exposed Docker daemon) becomes directly reachable from inside the container.docker exec(above) is the safe way to probe a loopback-bound server from outside the container.
Allow browser origins (CORS):
PW="$(openssl rand -hex 24)"
docker run --rm -p 127.0.0.1:4096:4096 -v "$PWD:/workspace" \
-e OPENCODE_SERVER_PASSWORD="$PW" \
agent-box-opencode:local serve --cors http://localhost:5173 --cors https://app.example.comProtect the server with HTTP basic auth, and treat this as required for any serve invocation, even one published to loopback only (anything else on your machine, or anyone with SSH access to it, can reach a loopback-bound port):
PW="$(openssl rand -hex 24)"
docker run --rm -d -p 127.0.0.1:4096:4096 -v "$PWD:/workspace" \
-e OPENCODE_SERVER_PASSWORD="$PW" \
agent-box-opencode:local serveThe username is fixed to opencode in V2 (the V1
OPENCODE_SERVER_USERNAME override is gone). If you do not set
OPENCODE_SERVER_PASSWORD, V2 generates one and prints
server password <value> on startup, so the server is never left
unauthenticated.
Mount the auth/sessions directory so logins and sessions survive across containers:
PW="$(openssl rand -hex 24)"
docker run --rm -d -p 127.0.0.1:4096:4096 -v "$PWD:/workspace" \
-v "$HOME/.local/share/opencode:/home/agent-box/.local/share/opencode" \
-e OPENCODE_SERVER_PASSWORD="$PW" \
agent-box-opencode:local serveOn native Linux with a host uid other than 10001, add
--user "$(id -u):$(id -g)" --group-add 0 (works the same in serve mode, no
root involved): PW="$(openssl rand -hex 24)" && docker run --rm -d --user "$(id -u):$(id -g)" --group-add 0 -p 127.0.0.1:4096:4096 -v "$PWD:/workspace" -e OPENCODE_SERVER_PASSWORD="$PW" agent-box-opencode:local serve.
Bind mounts keep host uid/gid. If your host uid differs from the image's
10001, the agent needs to write its config/data dirs (and, for git, avoid
"dubious ownership" on /workspace) as a uid it doesn't own by default.
Recommended: the arbitrary-uid recipe (no root, ever):
docker run -it --rm \
--user "$(id -u):$(id -g)" --group-add 0 \
-v "$PWD:/workspace" \
agent-box-opencode:local--user "$(id -u):$(id -g)"runs the container as your exact host uid and gid, so files the agent creates in/workspaceare owned by you, not by a container-internal uid.--group-add 0adds gid0as an extra group (not your primary group), which is all that's needed to write~/.config/opencodeand~/.local/share/opencodeinside the container. See "Why gid 0?" below for what this does and doesn't mean.- git's dubious-ownership check is a non-issue here: the image bakes
git config --system --add safe.directory '*'at build time, so it trusts any workspace regardless of uid; no runtime step needed. - Set this up once, not per run: put the command in a shell alias
or function (
alias agent-box='docker run -it --rm --user "$(id -u):$(id -g)" --group-add 0 -v "$PWD:/workspace" agent-box-opencode:local'), or use the Compose snippet below.
Legacy alternative: --user 0. Still supported, but no longer
recommended for new setups: it briefly runs the container as real root so
the entrypoint can rewrite its own uid/gid, while the recipe above never
uses root at all:
docker run -it --rm --user 0 -v "$PWD:/workspace" agent-box-opencode:localThe entrypoint rewrites the runtime user's uid/gid to the mount owner, marks
/workspace git-safe, then drops privileges before exec'ing OpenCode.
On Docker Desktop (macOS/Windows), ownership is squashed and the plain
default invocation (no --user flag at all) already works as-is; none of
the above is needed there.
If you're not familiar with Linux users/groups, here's the short version.
Every file has a numeric owner (uid) and a numeric group (gid). The
image can't predict which uid you'll run as, but it can pin one shared gid
in advance: it makes ~/.config/opencode, ~/.local/share/opencode, and
$HOME itself owned by group 0, with group-write permission
(chmod g=u). Linux then lets any uid that carries gid 0 (as its
main group, or as an extra one via --group-add 0) read and write those
directories, no matter what its own uid is.
# without --group-add 0:
$ docker run --user 1000:1000 agent-box-opencode:local run "..."
EACCES: permission denied, mkdir '/home/agent-box/.local/share/opencode/log'
# with --group-add 0:
$ docker run --user 1000:1000 --group-add 0 agent-box-opencode:local run "..."
# works — id inside the container shows: uid=1000 gid=1000 groups=0(root),1000
Gid 0 happens to be called "root" on most Linux systems, which can sound
alarming, but inside this container it confers no special power: there is
no sudo, no setuid binary, and nothing gid 0 can do beyond read/write
the few directories the image explicitly made group-writable. It is a
convenient, always-present group number every container has, borrowed here
as a "anyone with this group can write here" signal, not an admin flag. If
a security scanner in your environment flags runAsGroup: 0, use
--group-add 0 (gid 0 as a supplementary group) rather than --user X:0
(gid 0 as your primary group); both work identically for this image, and
the former keeps your primary gid as whatever your policy expects.
services:
agent:
image: agent-box-opencode:local
user: "${UID:-1000}:${GID:-1000}"
group_add:
- "0"
volumes:
- .:/workspace
stdin_open: true
tty: trueRun with UID=$(id -u) GID=$(id -g) docker compose run --rm agent (Compose
does not expand $(id -u) itself, so export it from the shell first).
The image is non-root, has no setuid binaries, and no way back to root once
the entrypoint drops privileges. But a container is not a sandbox by itself:
capabilities, the network namespace, and the root filesystem are only as
locked down as the flags you pass to docker run. The recipes below were
verified against this image; adopt them as your default invocation.
On Docker Desktop (macOS/Windows), the container runs inside a lightweight
VM; an escape reaches that VM, not your host filesystem, and bind-mount
ownership is squashed so the default non-root user already works. On native
Linux, the kernel is shared with your host. Use the arbitrary-uid
recipe (--user "$(id -u):$(id -g)" --group-add 0) rather than the legacy --user 0: it needs no root and no
capabilities at all (verified working with --cap-drop=ALL), so there is
no privileged window for an escape to land in, unlike --user 0, which
briefly runs the container as real root. Rootless Docker, dockerd --userns-remap, or Podman with --userns=keep-id remain worth adopting on
top of either recipe if available; they add a further layer by remapping
container uids away from real host uids entirely.
Default (non-root) path, verified working:
docker run -it --rm \
--cap-drop=ALL \
--security-opt=no-new-privileges \
--pids-limit=512 --memory=4g --cpus=2 \
-v "$PWD:/workspace" \
agent-box-opencode:localAdd, if you don't need persisted sessions (verified working; omit the tmpfs
on $HOME if you bind-mount ~/.local/share/opencode for persistence
instead, since that mount already gives you a writable, size-bounded path):
--read-only \
--tmpfs /tmp:rw,nosuid,nodev \
--tmpfs /home/agent-box:rw,nosuid,nodev,uid=10001,gid=10001Native-Linux arbitrary-uid path (see On native Linux (file
ownership)), the recommended native-Linux
recipe; unlike --user 0 below, it needs zero capabilities (verified
working with --cap-drop=ALL) and works with --read-only:
docker run -it --rm \
--user "$(id -u):$(id -g)" --group-add 0 \
--cap-drop=ALL \
--security-opt=no-new-privileges \
--read-only \
--tmpfs /tmp:rw,nosuid,nodev \
--tmpfs /home/agent-box:rw,nosuid,nodev,uid=$(id -u),gid=0,mode=0770 \
--pids-limit=512 --memory=4g --cpus=2 \
-v "$PWD:/workspace" \
agent-box-opencode:local(Omit the --read-only/--tmpfs lines if you don't need that level of
hardening; the recipe works identically without them, just with a writable
root filesystem.)
Legacy --user 0 path, kept for compatibility and no longer recommended
(see On native Linux (file ownership)).
This is the exact minimal capability set; dropping CAP_CHOWN breaks the
entrypoint's chown calls, a plain --cap-drop=ALL fails at setpriv's
setresuid with a non-obvious error, and dropping CAP_SETPCAP breaks the
entrypoint's own setpriv --bounding-set -all hardening step (that step
needs CAP_SETPCAP to clear the target process's bounding set, even
though the target ends up with none of these capabilities once it runs):
docker run -it --rm --user 0 \
--cap-drop=ALL --cap-add=CHOWN --cap-add=SETUID --cap-add=SETGID --cap-add=SETPCAP \
--security-opt=no-new-privileges \
--pids-limit=512 --memory=4g --cpus=2 \
-v "$PWD:/workspace" \
agent-box-opencode:local--read-only does not work with --user 0: the entrypoint needs a
writable /etc to rewrite /etc/passwd//etc/group. This is one more
reason to prefer the arbitrary-uid recipe above when you can.
- Never mount:
/var/run/docker.sock(equivalent to unrestricted host root; see the note below if you actually need Docker-outside-of-Docker),/,$HOMEas a whole,~/.sshas a whole,~/.aws,~/.kube,~/.docker. - Never pass:
--privileged,--pid=host,--ipc=host,--security-opt seccomp=unconfined,--cap-add=SYS_ADMIN. Don't forwardSSH_AUTH_SOCKinto the container either: it lets the agent authenticate as you anywhere your agent forwarding reaches, with no key file to revoke. - Do instead: mount a single dedicated, revocable deploy key read-only
(
-v "$HOME/.ssh/id_agentbox:/home/agent-box/.ssh/id_ed25519:ro"), or prefer an HTTPS token scoped to the one repo you're working on, passed with-e. Mount the narrowest directory the task actually needs, and add:roto any mount the agent must not write to. - git-over-SSH and an arbitrary uid:
sshrefuses to run as a uid it cannot look up in/etc/passwd(e.g.--user 999:0with no such uid baked into the image). The entrypoint self-heals this by appending a passwd entry for the running uid on first use, sossh/whoamiwork normally, with no action needed on your part. If you also pass--read-onlywithout a writable/etc, that self-heal can't run; either accept that SSH-based git won't work in that combination, or bind-mount your host's own passwd file read-only instead:-v /etc/passwd:/etc/passwd:ro. docker.sockif you really need it:ensure_docker_accessin both entrypoints supports the Docker-outside-of-Docker pattern when running as--user 0(mount the host's socket, the entrypoint grants the runtime user group access to it automatically). On the recommended arbitrary-uid path this auto-wiring needs root and doesn't run, so add the socket's own group yourself:--group-add "$(stat -c %g /var/run/docker.sock)". Either way, treat that mount as equivalent to handing the agent root on the Docker host, because it is: a container started through that socket can trivially mount/and read/write anything. Only do this in a disposable VM, never on a workstation with anything sensitive on it.
Verified: with default bridge networking the container can reach services
bound to your host's loopback interface (e.g. via host.docker.internal),
and the agent has unrestricted egress by default (it ships curl).
Unrestricted egress is another way to reach the host: the agent can read
cloud-metadata endpoints on a cloud VM, reach a
TCP-exposed Docker daemon, or exfiltrate repository contents to any endpoint
the model chooses to call.
- Use a dedicated user-defined bridge network rather than the default one.
- Use
--network=nonefor anything that doesn't need model/API access (e.g.--version, or local-model setups reachable only via a mounted socket). - For sensitive repositories, route egress through an allow-listing proxy
(
-e HTTPS_PROXY=...) so only your model provider's endpoint is reachable. - Never pass
--network hostto work around a loopback-boundserve(see Server): it removes the container's network namespace entirely, making every host-loopback service directly reachable from inside the container.
--read-onlyplus the tmpfs mounts above prevents the agent from persisting tooling or tampering with/usr/local/bin/opencodeor/etcbetween invocations. Rely on the default seccomp profile too: never pass--security-opt seccomp=unconfinedto work around a tool that seems to need it; narrow the actual cause instead.--pids-limit,--memory, and--cpusbound the blast radius of a runaway build, an agent stuck in a retry loop, or a shell fork bomb the agent's own tool-calling issues, none of which requires a container escape to hurt your host.- A bind mount has no container-level disk quota: the agent can fill your
host disk by writing into
/workspaceor a persisted volume. Monitor free space the same way you would for any other process writing to that path.
| Property | Value |
|---|---|
| Base | cgr.dev/chainguard/wolfi-base (digest-pinned) |
| User | opencode, uid/gid 10001 (arbitrary-uid capable via gid 0; root only needed for the legacy --user 0 path) |
| Binary | /usr/local/bin/opencode (root-owned, 0755, from the official installer) |
| Data dirs | $HOME=/home/agent-box (writable), WORKDIR=/workspace |
| Size | Not published; it moves with every bundled agent release. Measure your own build: How big is it? |
| Entry | opencode-entrypoint.sh → opencode; default CMD ["--help"] |
| Exposed | 4096/tcp (default opencode serve port; metadata only) |
Runtime packages: bash, curl, git, openssh-client, setpriv
(util-linux's setpriv, used to drop root privileges to the runtime user at
container start), plus version-pinned agent-efficiency tooling: ripgrep
(fast, gitignore-aware search), jq and yq (JSON/YAML querying and
validation), patch and diffutils (applying unified diffs). Pin each with
its own --build-arg (RIPGREP_VERSION, JQ_VERSION, YQ_VERSION,
PATCH_VERSION, DIFFUTILS_VERSION), same reproducibility rationale as
OPENCODE_VERSION. The build stage runs the official installer
(curl -fsSL https://opencode.ai/v2/install | bash) and copies only the binary
into the final image; the runtime layer has no install toolchain.
Also bundled: fff-mcp
(/usr/local/bin/fff-mcp, root-owned, 0755), a static MCP server binary for
fast file search. Installed as a pinned, checksum-verified GitHub release
download (FFF_MCP_VERSION, FFF_MCP_SHA256_AMD64/FFF_MCP_SHA256_ARM64),
deliberately not via the vendor's curl | bash installer, since that
script is itself fetched unpinned and its checksum verification fails open
in some fallback branches. Same reproducible, checksum-verified pattern as
the Liberica JDK/mvnd installs in java/java-25.Dockerfile.
Also bundled: shellcheck
(/usr/local/bin/shellcheck, root-owned, 0755), a static analyzer for
sh/bash scripts, so the agent can lint the shell it writes instead of
eyeballing it. ShellCheck has no Wolfi package (apk search shellcheck
returns nothing; Wolfi ships no GHC toolchain), and Alpine packages cannot be
mixed into a Wolfi image, so this image installs upstream's own statically
linked release binary with the same pinned-version-plus-SHA256 pattern
(SHELLCHECK_VERSION, SHELLCHECK_SHA256_AMD64/SHELLCHECK_SHA256_ARM64).
Its license text and a Corresponding-Source pointer are copied to
/usr/share/doc/shellcheck/ (LICENSE.txt, SOURCE.txt), matching Wolfi's
own convention for package licenses. It is the heaviest single addition to the
image on arm64; see How big is it?, and drop the
shellcheck ARG/COPY steps if that cost does not suit you (nothing else in
the image depends on them).
No fixed figure is published here on purpose. The size is dominated by the agent binary, which changes every release, and the last hardcoded number in this table sat stale for two weeks while two new tools were added to the image. Measure your own build instead:
docker build -f opencode/opencode.Dockerfile -t agent-box-opencode:local .
# Total, uncompressed (what the node's disk actually pays):
docker images --format '{{.Size}}' agent-box-opencode:local
# Who spends it (newest layers first; the layers below this cut all come from
# the Wolfi base, built by `apko`):
docker history --format '{{.Size}} {{.CreatedBy}}' agent-box-opencode:local | head -20Three traps when reading those numbers:
- Units:
docker imagesanddocker historyprint decimal MB (1000-based), whereas dividingdocker image inspect --format '{{.Size}}'bytes by 1,048,576 gives binary MiB (roughly 4.6% smaller for the same byte count). Never mix the two in one sentence. - Registries compress each layer, so a pull is much cheaper than the on-disk figure: ShellCheck's 55 MB arm64 layer transfers about 12 MB, and its 16 MB x86_64 counterpart about 4 MB.
- Architecture: the same pinned release differs per arch, so always state the arch with the number. Proof from the pinned ShellCheck v0.11.0 assets: 16,213,136 bytes (x86_64) vs 55,043,352 bytes (aarch64), 3.4x apart.
The omp variant is the same shape with a different agent binary. The
java/java-25.Dockerfile worked example lands near 1 GB, and that cost is
the JDK/mvnd/Python layer you add, not the base.
omp/omp.Dockerfile builds the same hardened box around
omp (Oh-My-Pi) instead of OpenCode: same digest-pinned
Wolfi base, same non-root uid 10001 with bind-mount uid/gid adaptation, same
bundled tooling (including fff-mcp and shellcheck, installed the same
pinned, checksum-verified way). The agent is installed via the official installer
(curl -fsSL https://omp.sh/install | sh), pinned to a known-good release
(OMP_VERSION), and only the binary is copied into the final image.
docker build -f omp/omp.Dockerfile -t agent-box-omp:local .
# Pin a different omp release (bump OMP_VERSION and VERSION together so the
# installed binary and the OCI version label stay in sync)
docker build -f omp/omp.Dockerfile \
--build-arg OMP_VERSION=v<x.y.z> --build-arg VERSION=v<x.y.z> \
-t agent-box-omp:v<x.y.z> .
# Interactive TUI
docker run -it --rm -v "$PWD:/workspace" agent-box-omp:local
# One-shot prompt
docker run -it --rm -v "$PWD:/workspace" agent-box-omp:local -p "explain this repo"
# Persist config and sessions across containers (entire directory or agent subfolder)
docker run -it --rm -v "$PWD:/workspace" \
-v "$HOME/.omp:/home/agent-box/.omp" agent-box-omp:local
# Or persist only the agent directory:
# docker run -it --rm -v "$PWD:/workspace" \
# -v "$HOME/.omp/agent:/home/agent-box/.omp/agent" agent-box-omp:localDifferences from the OpenCode image:
| Property | omp image |
|---|---|
| Binary | /usr/local/bin/omp (root-owned, 0755, from the official installer) |
| User | omp, uid/gid 10001 (arbitrary-uid capable via gid 0; root only needed for the legacy --user 0 path) |
| Config/data dir | $HOME/.omp (/home/agent-box/.omp) or $HOME/.omp/agent; mount to persist config and sessions |
| Entry | omp-entrypoint.sh → omp; default CMD ["--help"] |
| Server mode | none; omp's entry points are the TUI, one-shot -p, RPC, and ACP over stdio, so the image has no EXPOSE and the entrypoint injects no --hostname |
On native Linux, use the arbitrary-uid recipe (--user "$(id -u):$(id -g)" --group-add 0) exactly as described in On native Linux (file
ownership); the legacy --user 0 path
also still works unchanged.
You can layer extra tools (Python, Java, Maven, etc.) on top of this image by using it as a base in your own Dockerfile:
FROM agent-box-opencode:local
# The runtime stage ends on `USER opencode` (uid 10001), so switch back to
# root to install packages, then drop privileges again.
USER root
# Pin versions the same way the base image does, so your build stays
# reproducible when Wolfi ships new stable builds.
ARG PYTHON_VERSION=3.13
ARG OPENJDK_VERSION=17
RUN apk add --no-cache \
python-3.13 \
openjdk-17 \
maven-3.9
# Wolfi's JDK packages install under /usr/lib/jvm and do NOT add java to PATH
# or set JAVA_HOME — do both explicitly (Maven needs JAVA_HOME).
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk \
PATH="${JAVA_HOME}/bin:${PATH}"
USER opencodeThings to keep in mind:
- Switch to
USER rootbeforeapk add, then back to the base image's user. The base image is non-root by default; installing packages needs root, but the final image should stay non-root unless you have a specific reason not to. That user isopencodeinagent-box-opencodeandompinagent-box-omp(both uid 10001, both$HOME=/home/agent-box), and the name must exist in the image, sincedocker runresolves it through/etc/passwdbefore the container starts. - Verify Wolfi package names before installing. This image is built on
Chainguard Wolfi, whose package names sometimes differ from Alpine's (or
don't exist at all). Check first:
docker run --rm cgr.dev/chainguard/wolfi-base:latest sh -c 'apk search <pkg>' - Pin package versions for reproducibility. Wolfi is a rolling
distribution; an unpinned
apk add mavengives you whatever is current. Either pin explicit versions (maven=3.9.x-rN) like the base image'sARG/--build-argpattern, or accept that rebuilds may drift. - Set toolchain env vars explicitly.
JAVA_HOMEis not set by the Wolfi JDK packages; Maven and many build tools need it. Add the JDK'sbintoPATHif you want plainjava/javacon the command line. ENTRYPOINT/CMDare inherited automatically. Unless you want different default behavior, leave them as-is so your derived image still runs OpenCode. OverrideCMD(orENTRYPOINT) explicitly if you need to.- Preserve ownership under
/home/agent-box. Anything youCOPYor create there should be group-owned by gid0with group permissions mirroring the owner's, e.g.COPY --chown=opencode:0 --chmod=775 ...or aRUN chown -R opencode:0 ... && chmod -R g=u ...step, matching the base image's own arbitrary-uid layout (see Why gid 0?).--chown=opencode:opencode(the pre-arbitrary-uid pattern) still lets the default uid-10001 user write it, but breaks writability for anyone using the recommended--user "$(id -u):$(id -g)" --group-add 0recipe. - Give build caches a writable home. Maven (
.m2), pip (.cache/pip), and Gradle (.gradle) all write under$HOMEby default, which is/home/agent-boxand writable, so this works out of the box. To persist caches across containers, mount a volume, e.g.-v maven-cache:/home/agent-box/.m2. - Reuse the TLS-intercepting-proxy pattern if needed. If you're behind a
corporate MITM proxy, mount an external CA the same way this repo's
opencode/opencode.Dockerfile does (see Building behind a TLS-intercepting
proxy) before your own
apk add/curlcalls. - A JVM needs the CA imported twice. A JDK ships its own trust store (a
copy of
cacertsunder$JAVA_HOME/lib/security), separate from/etc/ssl/certs/ca-certificates.crt. Appending the proxy CA to the system bundle makescurl/apktrust it but does NOT makejava/mvndtrust it: without a secondkeytool -importcert ... -keystore "$JAVA_HOME/lib/security/cacerts" -storepass changeitstep after installing the JDK, JVM-side HTTPS calls (e.g. Maven resolving dependencies) still fail withPKIX path building failed. Seejava/java-25.Dockerfilefor the worked-example step. - Expect the image to grow. Toolchains like a JDK and Maven add real weight (often 300-500 MB combined); the "minimal" sizing in this README applies to the unmodified base image, not your derived one.
- Don't reintroduce a path back to root. The base image deliberately
ships no setuid/setgid binaries and no
sudo/su/doas, so once the entrypoint drops privileges viasetprivthere is nothing in the image that can regain root, reinforced by--no-new-privson thatsetprivcall (see Hardening). Installing a package that ships a setuid binary or file capabilities (rare, but someapk addpackages do) as root in your derivedDockerfilecan reopen that path. Check what you installed:docker run --rm --entrypoint sh <your-image> -c "find / -xdev \( -perm -4000 -o -perm -2000 \) -type f 2>/dev/null"should print nothing.
This repo ships java/java-25.Dockerfile as a worked example of a derived
image: it layers BellSoft Liberica JDK 25, Maven Daemon (mvnd, which bundles
Maven), and Python 3.13 on top of the base image. The same file builds two
images, one per base agent. It demonstrates the pattern recommended above:
pinned, checksum-verified tarball downloads installed system-wide for tools
Wolfi does not package (SDKMAN was considered and rejected: it is per-user,
writes to $HOME, and depends on a live version catalog, so builds are not
reproducible).
Build and verify both:
docker build -f opencode/opencode.Dockerfile -t agent-box-opencode:local .
docker build -f omp/omp.Dockerfile -t agent-box-omp:local .
# opencode base — BASE_USER is mandatory and must match the base image's
# runtime user; the build fails fast if it's omitted.
docker build -f java/java-25.Dockerfile \
--build-arg BASE_IMAGE=agent-box-opencode:local --build-arg BASE_USER=opencode \
-t agent-box-opencode-java:local .
docker run --rm --entrypoint bash agent-box-opencode-java:local \
-c 'opencode --version && java -version && mvnd --version && python3 --version'
# omp base — same layer, different agent. The runtime user the base image
# defines differs (`omp` instead of `opencode`), so point BASE_USER at it.
docker build -f java/java-25.Dockerfile \
--build-arg BASE_IMAGE=agent-box-omp:local --build-arg BASE_USER=omp \
-t agent-box-omp-java:local .
docker run --rm --entrypoint bash agent-box-omp-java:local \
-c 'omp --version && java -version && mvnd --version && python3 --version'The JDK build is pinned by LIBERICA_VERSION plus the per-arch
LIBERICA_SHA1_* values in the Dockerfile; override them together (fetch new
SHA1s from api.bell-sw.com/v1/liberica/releases, arch=x86/arch=arm) to
move to a different Liberica release. The install path and JAVA_HOME are
hardcoded to liberica-25, so rename those too when changing major versions.
After building, confirm your tooling works and the inherited behavior is intact:
docker build -t my-agent-box .
docker run --rm my-agent-box --version # OpenCode still runs
docker run --rm my-agent-box run "run: java -version && mvn -version && python3 --version"The arbitrary-uid recipe, the legacy --user 0 uid-adaptation path, and
serve hostname injection described above all work unchanged in derived
images, since they live in the inherited entrypoint. See "Preserve
ownership under /home/agent-box" above if your derived Dockerfile adds
anything under $HOME.
OpenCode keeps provider credentials in its data directory (inside the
container: /home/agent-box/.local/share/opencode/; V2 stores them in
opencode.db there and imports a legacy auth.json on first run). Either
persist that directory as a volume (shown above) or pass keys per-run with
-e:
docker run -it --rm -v "$PWD:/workspace" -e ANTHROPIC_API_KEY agent-box-opencode:localNote: on native Linux with the recommended --user "$(id -u):$(id -g)" --group-add 0 recipe (or the legacy --user 0), the container writes
session/auth files as your own uid, so a persisted directory you create
yourself is already writable. The only case needing a fix is a directory an
earlier run created under the plain default (uid 10001, no --user
flag): fix its ownership once with
sudo chown -R "$(id -u):$(id -g)" ~/.local/share/opencode, or the agent
will not be able to write sessions/auth.
Some skills or MCP tools need their own credentials at runtime: a
GITHUB_TOKEN, a Jira/Confluence API token, a database password, etc. The
same -e mechanism used for provider API keys above works for any secret
env variable.
Never source ~/.bashrc (or any interactive shell rc file) into the
container: it is not a portable KEY=VALUE list, and mixing secrets into
shell startup files is fragile. Instead, pick one of:
# Forward a variable already exported in your shell (value stays in your
# shell env, never typed twice, never leaks into container image layers)
export GITHUB_TOKEN=ghp_xxx
docker run -it --rm -v "$PWD:/workspace" -e GITHUB_TOKEN agent-box-opencode:local
# Or collect several secrets into a plain env file (KEY=VALUE per line, no
# quotes, no `export`, no shell logic) and pass it with --env-file
cat > ~/.config/agent-box/agent.env <<'EOF'
GITHUB_TOKEN=ghp_xxx
ATLASSIAN_PERSONAL_TOKEN=xxxx
ATLASSIAN_EMAIL=you@example.com
EOF
chmod 600 ~/.config/agent-box/agent.env
docker run -it --rm -v "$PWD:/workspace" \
--env-file ~/.config/agent-box/agent.env \
agent-box-opencode:localKeep the env file out of version control and readable only by you
(chmod 600). This matches the repo convention of never baking secrets into
the image or its ENV/ARG: secrets are always supplied at docker run
time, whether they are model provider keys or skill/tool tokens.
Apache-2.0; see LICENSE. Bundled third-party tools keep their own licenses; see Licensing of bundled third-party tools for the one copyleft component (ShellCheck, GPLv3) and what it means when you redistribute an image built from this repo.
ShellCheck is GPLv3. That is unremarkable in itself: the Wolfi base already
ships copyleft packages (bash and diffutils GPL-3.0-or-later, busybox and
apk-tools GPL-2.0, glibc LGPL-2.1), and apk installs their license text for
you. ShellCheck is the first copyleft tool added outside the package
manager, so its notices have to be placed by hand. What it means in practice:
- Your files are unaffected. Separate programs in one filesystem are "mere aggregation" (GPLv3 §5). Your Dockerfiles, entrypoint scripts, config, and application code keep their own licenses; this repo stays Apache-2.0.
- Obligations attach only when you distribute the image (push to a registry, ship it to customers). Running it yourself, including as an internal service, is not distribution, and ShellCheck moved from AGPL to GPL in v0.3.8, so there is no network-use clause to worry about either.
- When you do distribute, you must ship the license text (done), keep the
notices, and be able to hand over ShellCheck's Corresponding Source; the
SOURCE.txtin the image points at the exact release's source archive. You may add no further restrictions on ShellCheck, and any patch you make to ShellCheck's own source must stay GPLv3. - One real trap: call it as a command, as the agent does. Linking against ShellCheck's Haskell library would make your program a derivative work.