Why
My first agent was Kilo: it could run scripts on my machine, but it was not convenient to use. That pushed me to look at what alternatives exist and what they can do.
I wanted:
- The agent not to be tied to an IDE and to be able to work in a terminal or browser.
- The agent not to be tied to a single provider.
- The agent to run in an isolated environment: do whatever it wants, but not affect the host system.
In the end I chose OpenCode as the most popular and fast-growing open source project.
OpenCode already has 230k stars on GitHub.
It has no built-in isolation, but you can run it in a docker container.
Architecture
The whole setup rests on three files:
Dockerfile: the agent image with the base system, tools (Go, Python, Node, ripgrep, and so on) andopencodeplus extra tooling (mcp, skills, plugins).docker-compose.yaml: service definitions foropencodeanddocker-dind.opencode.json: the agent config (models, providers, plugins, MCP, and the rest).
The opencode service is the agent itself.
The docker-dind service is an isolated Docker Engine. It lets the agent spin up separate containers to run tasks, build and test.
Sessions, settings and cache live in volumes (opencode-data, serena-data, opencode-cache, and others), so recreating the container does not touch them. The agent’s history and memory outlive the container itself.
The diagram shows how the agent connects to all the tools it needs.
opencode.json
The agent config: default model, plugins, providers and MCP servers. Values in curly braces ({env:...}) are substituted from environment variables.
{
"$schema": "https://opencode.ai/config.json",
"share": "disabled",
"model": "{env:OPENCODE_MODEL}",
"update": "notify",
"lsp": true,
"formatter": true,
"websearch": false,
"experimental": {
"todo": true
},
"plugins": [
"opencode-mem@latest",
"@dietrichgebert/ponytail",
"superpowers@git+https://github.com/obra/superpowers.git"
],
"agents": {
"title": { "model": "{env:OPENCODE_AGENT_TITLE_MODEL}" }
},
"providers": {
"lmstudio": {
"name": "LM Studio (local)",
"package": "aisdk:@ai-sdk/openai-compatible",
"settings": { "baseURL": "http://host.docker.internal:1234/v1" }
},
"openrouter": {
"name": "OpenRouter",
"settings": { "apiKey": "{env:PROVIDER_OPENROUTER_API_KEY}" }
},
"opencode-go": {
"options": { "baseURL": "https://opencode.ai/zen/v1" }
}
},
"mcp": {
"servers": {
"codebase-memory": {
"type": "local",
"command": ["/usr/local/bin/codebase-memory-mcp"]
},
"github": {
"type": "local",
"command": ["/root/.local/bin/github-mcp-server", "stdio"],
"environment": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "{env:MCP_GITHUB_API_KEY}",
"GITHUB_TOOLSETS": "all"
}
},
"grafana.net": {
"type": "local",
"command": ["/root/.local/bin/uvx", "mcp-grafana"],
"environment": {
"GRAFANA_URL": "{env:MCP_GRAFANA_URL}",
"GRAFANA_SERVICE_ACCOUNT_TOKEN": "{env:MCP_GRAFANA_API_KEY}"
},
"disabled": true
},
"ssh-mcp": {
"type": "local",
"command": ["ssh-mcp"],
"disabled": true
},
"browse": {
"type": "local",
"command": ["/root/.local/bin/browse", "mcp"],
"environment": { "OPENCODE_BROWSER_RUNTIME": "auto-update" }
},
"graphify": {
"type": "local",
"command": ["graphify-mcp", ".graphify-out/graph.json"],
"cwd": ".",
"environment": { "GRAPHIFY_OUT": ".graphify-out" }
}
}
}
}
Dockerfile
The agent image is based on Ubuntu and consists of base utilities for working with code and utilities for opencode.
FROM ubuntu:26.10
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& apt-get update \
&& apt-get install --yes --no-install-recommends \
build-essential \
ca-certificates \
curl \
dnsutils \
docker.io \
fd-find \
gdb \
git \
golang \
jq \
libarchive-tools \
ncat \
nodejs \
npm \
openssh-client \
python3 \
python3-pip \
python3-venv \
ripgrep \
tzdata \
unzip
ENV PATH="/root/go/bin:/root/.local/bin:${PATH}"
RUN curl -fsSL https://opencode.ai/v2/install | bash
RUN curl -fsSL https://opencode.ai/browse/install | bash -s -- --remote
RUN --mount=type=cache,target=/root/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go install golang.org/x/tools/gopls@latest \
&& go install github.com/go-task/task/v3/cmd/task@latest \
&& go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
RUN curl -fsSL https://bun.com/install | bash
RUN --mount=type=cache,target=/root/.cache/uv \
curl -fsSL https://astral.sh/uv/install.sh | sh \
&& uv tool install git+https://github.com/oraios/serena \
&& uv tool install "graphifyy[all]" && graphify install --platform opencode
RUN --mount=type=cache,target=/root/.npm \
npm install -g ssh-mcp \
&& mkdir -p /root/.config/ssh-mcp \
&& chmod 700 /root/.config/ssh-mcp
RUN curl -fsSL "https://github.com/github/github-mcp-server/releases/latest/download/github-mcp-server_Linux_x86_64.tar.gz" \
| tar -xz -C /root/.local/bin github-mcp-server
RUN curl -fsSL "https://github.com/DeusData/codebase-memory-mcp/releases/latest/download/codebase-memory-mcp-linux-arm64-portable.tar.gz" \
| tar -xz -C /usr/local/bin codebase-memory-mcp
docker-compose.yaml
Docker runs opencode serve on port 49374. TUI and WebUI clients connect through this port.
services:
opencode:
build:
context: .
ports:
- "127.0.0.1:49374:49374"
- "127.0.0.1:19988:19988"
env_file:
- ~/.config/opencode/.env
restart: unless-stopped
depends_on:
- docker-dind
environment:
OPENCODE_SERVER_PASSWORD: ${OPENCODE_SERVER_PASSWORD}
DOCKER_HOST: tcp://docker-dind:2375
volumes:
- ./root/.config/opencode:/root/.config/opencode
- ./root/.config/ssh-mcp:/root/.config/ssh-mcp
- ./root/.gitconfig:/root/.gitconfig
- ./root/.gitconfig_private:/root/.gitconfig_private
- ./root/_gitignore:/root/.gitignore
- opencode-data:/root/.local/share/opencode
- serena-data:/root/.serena
- opencode-mem-data:/root/.opencode-mem/data
- opencode-cache:/root/.cache/opencode
- codebase-memory-cache:/root/.cache/codebase-memory-mcp
command:
- /root/.opencode/bin/opencode
- serve
- --hostname=0.0.0.0
- --port=49374
- --log-level=warn
- --print-logs=true
networks:
- opencode
docker-dind:
image: docker:29-dind
restart: unless-stopped
privileged: true
command: ["dockerd", "--host=tcp://0.0.0.0:2375", "--tls=false"]
networks:
- opencode
volumes:
- docker-data:/var/lib/docker
networks:
opencode:
volumes:
docker-data:
opencode-data:
serena-data:
opencode-mem-data:
opencode-cache:
codebase-memory-cache:
Running
# 1. Add all the necessary environment variables to .env
vim ~/.config/opencode/.env
# 2. Add email/name to the private gitconfig: the identity the agent will commit under
vim ~/.config/opencode/.gitconfig_private
# 3. Run
docker compose up --build -d
How to connect
You can connect from a terminal or a browser:
- Web UI:
http://localhost:49374(the port is bound to loopback, not reachable from outside). The password is set inOPENCODE_SERVER_PASSWORD. - TUI:
opencode --server http://localhost:49374
Plugins
Besides models and MCP, opencode.json enables plugins:
- opencode-mem: long-term local memory that persists across sessions.
- ponytail: a “lazy senior” mode (
/ponytail) that keeps changes minimal. - superpowers: a set of skills for brainstorming, debugging, planning, code review, and more.
MCP
MCP servers give the agent access to the outside world.
Mine are mostly for working with code:
- Serena searches and edits code by symbols rather than lines.
- GitLab gives access to repositories in GitLab.
- Grafana pulls metrics, traces and application logs.
- GitHub MCP searches and works with code on GitHub.
- codebase-memory keeps memory of the codebase: an index of symbols and the relationships between them.
- graphify builds a call graph of the project so you can see how functions connect.
- browse controls a browser: it opens a page, reads it and interacts with it.
- ssh-mcp connects over SSH to remote machines.
Providers
OpenCode supports many providers, and the model is set via the OPENCODE_MODEL variable, so you can change it without editing the config.
Local models (LM Studio) are also connected, but I don’t have the horsepower to run them at a reasonable speed, so I use cloud providers.
Statistics
Over two months there were 762 sessions, 1.2k subagents and 9.3b tokens spent.
❯ opencode stats --server http://localhost:49374 ; opencode stats --server http://localhost:49374 --cost
opencode stats · 2026 so far · all projects
activity
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Mo ·······································░▒█░▓█░▓█
Tu ·······································░▒▓░▓█▓▓▓
We ·······································▒░▒░▓█▒▓█
Th ········································░▓▒▒▒▓█▓▓
Fr ········································░▒▒░█▓██▒
Sa ·······································░░░░▒▒█░█
Su ·······································▒▓▓▒▒████
less ·░▒▓█ more
762 sessions · 1.2k subagents
7.3k prompts · 96.7k steps · 9.3b tokens
97.4% tool success · 63 active days · best streak 63 days
opencode.ai
2026 so far · all projects
COST & TOKENS
input 1.7b
output 32.5m
reasoning 29.2m
cache read 7.6b
cache write 571.7k
cached input 81.9%
Summary
The setup works. OpenCode is convenient in a terminal and in a browser, and it is actively developed: something useful lands almost every week. On 2026-11-29, for instance, an automation feature shipped, so the agent can now run tasks on a schedule or on triggers.
What’s next
Next I want to try harness agents that lean on autonomous work.