Skip to main content
The OpenCode Container provides a pre-configured Docker image for running OpenCode as a coding backend for Station agents. It enables AI-powered code generation in isolated, reproducible environments.

Why Use the Container?

Isolated Environment

Run OpenCode in a container without affecting your local system. Perfect for CI/CD and testing.

Pre-configured

Comes with Bun runtime, Git, and Station plugin pre-installed.

OAuth Support

Use Claude Max subscription via OAuth instead of API keys.

NATS Integration

Built-in Station plugin for NATS-based task dispatch.

Quick Start with Station CLI

The easiest way to run OpenCode in a container is using the Station CLI. This manages Docker Compose for you and uses your existing Anthropic OAuth credentials.
1

Start the Sandbox

This starts OpenCode on port 4099 (to avoid conflicts with native OpenCode on 4096).
2

Configure Station

3

Run Your Agent

Management Commands

Custom Port

With NATS (CloudShip Orchestration)

The Station CLI method uses ghcr.io/cloudshipai/opencode-station:latest which includes the Station NATS plugin pre-installed.

Manual Docker Setup

If you prefer manual Docker control, use the steps below.

1. Pull the Image

2. Run with API Key

3. Test the Connection

Authentication Options

Option 1: API Keys

Pass API keys as environment variables:

Option 2: OAuth (Claude Max)

For Claude Max subscribers, use OAuth authentication instead of API keys:
1

Login on Host

Run opencode auth login on your host machine to generate OAuth credentials:
2

Mount Credentials

Mount only the auth.json file (read-only) into the container:
Mount only auth.json, not the entire ~/.local/share/opencode directory. OpenCode needs to write to its storage subdirectory.

Docker Compose

Basic Setup

With OAuth (Claude Max)

Full Stack with NATS

For Station integration with NATS-based task dispatch:

Configuration

OpenCode Config File

Create a custom opencode.json for the container:
Mount it into the container:

Available Models

Environment Variables

Building Custom Image

For Station integration with the NATS plugin:

Dockerfile

Entrypoint Script

Build and Run

Using with Station

Station can connect to the OpenCode container via two backends:

Option 1: HTTP Backend (Direct)

Station calls OpenCode’s HTTP API directly. Simple setup, good for local development.

Option 2: NATS Backend (Plugin-based)

Station publishes tasks to NATS, the Station plugin in the container receives them and executes via OpenCode. Better for distributed setups.

Create a Coding Agent

The agent definition is the same regardless of backend - just enable coding:
Notice the agent doesn’t specify backend: opencode or backend: opencode-nats. The backend is determined by Station’s config, making agents portable across different deployments.

Run the Agent

Testing

Health Check

Create Session

Send Message

Troubleshooting

OAuth Token Not Working

Re-run opencode auth login on your host to refresh the token, then restart the container.

Read-Only Filesystem Error

If you see EROFS: read-only file system errors:
Cause: You mounted the entire ~/.local/share/opencode directory as read-only. Fix: Mount only auth.json:

Empty Response from API

If API calls return 200 OK but with empty body:
  1. Check container logs: docker logs <container>
  2. Verify model is configured in opencode.json
  3. Ensure API key or OAuth credentials are valid

Container Can’t Reach NATS

Next Steps

OpenCode Backend

Configure Station to use OpenCode

Docker Deployment

Deploy Station with Docker

Sandbox Execution

Run code in isolated containers

Workflows

Multi-step agent orchestration