Deploy OpenCode Agents

Primary agents and subagents in your hosted OpenCode

Deploy OpenCode Agents

Just deployed

/data

Deploy and Host self hosted OpenCode Agents (Self-Hosted AI Coding Agent with Custom Agents and Subagents) on Railway

This template runs a self-hosted OpenCode server with agents enabled, including the built-in Build and Plan primary agents and the General and Explore subagents.

About Hosting OpenCode Agents open-source software on Railway (self hosted OpenCode custom agents template)

Your agent definitions, prompts and session history live on your own volume, not on someone else's servers.

Railway handles the container, the public domain, HTTPS and the volume, so you only manage the agents themselves.

Why Deploy OpenCode Agents, the Claude Code subagents alternative on Railway (Railway Free Trial)

Claude Code subagents only run on Anthropic models and bill through an Anthropic account.

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying OpenCode Agents on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

Railway vs Other Hosting Providers and VPS for OpenCode Agents self hosting

Railway runs the OpenCode server, web UI and volume as one service, while other providers leave that setup to you.

ProviderWhat You Get with RailwayWhat You Get with the Other Provider
DigitalOceanA managed container with HTTPS, a persistent volume and dashboard variables.A Droplet you fully control, with your own firewall, proxy and TLS.
AWSOne service deployed from the template, with no VPC or IAM setup first.Deep networking and scaling control, but you wire up EC2 or ECS and certificates.
HetznerManaged deploys and redeploys, with the volume and password handled for you.Low cost per core, with you managing the OS, Docker and updates.

A VPS suits custom hardware or network rules, while Railway gets a working agent server running sooner.

Common Use Cases for hosted OpenCode Agents

  • Read-only code reviewer subagent: Define a subagent with permission edit set to deny and bash set to ask, then mention @review on a diff or file. It comments without touching the code.
  • Docs writer limited to markdown: Create a docs agent whose prompt restricts it to .md files, with edit allowed and bash denied. The agent file lives under /data/home/.config/opencode/agents, so it survives redeploys.
  • Test runner with limited commands: Use a bash permission with glob patterns so the agent can run npm test or pytest and nothing else. Everything outside that list is denied.
  • Cheaper model for exploration: Point an Explore-style subagent at a smaller model using the model option, while your Build agent keeps the stronger one. Searching a repo rarely needs top-tier reasoning, so this trims cost.
  • Security audit agent: Give a subagent a prompt focused on injection, secrets and unsafe dependencies, with edit and bash denied. You get a sceptical second opinion on code the primary agent just wrote.

Dependencies for OpenCode Agents Docker hosted on Railway

OpenCode Agents runs as one service built from the official OpenCode image, with one volume that holds your projects and agent definitions.

Deployment Dependencies for Managed OpenCode Agents Service (AI Coding Agent)

The template deploys one service, opencode, from ghcr.io/onepush-dev/opencode:1.19.3. It exposes a public domain on port 4096 and mounts one volume at /data.

Implementation Details for OpenCode Agents (Using OpenCode official docker image)

OPENCODE_SERVER_PASSWORD is generated at 32 characters, and OPENCODE_SERVER_USERNAME defaults to opencode.

How does OpenCode Agents compare against other ways to build specialised coding agents

OpenCode agents vs Claude Code subagents (Claude Code Alternative)

  • Model choice: Each OpenCode agent picks its own provider/model id, so a cheap model can run a read-only explorer. Claude Code subagents are tied to Anthropic models.
  • Where it runs: OpenCode serves a web UI on your own host, so agents work from any browser. Claude Code runs in your terminal on your machine.
  • Where Claude Code wins: It is more polished and tightly integrated with Anthropic's tooling, which is smoother if you already pay for Claude.

OpenCode vs Cursor custom modes (Cursor Alternative)

  • Openness: OpenCode is MIT licensed and you can change the agent logic. Cursor is a proprietary VS Code fork.
  • Permissions: OpenCode sets edit, bash and webfetch to allow, ask or deny per agent, so a reviewer can be truly read-only.
  • Where Cursor wins: Its editor experience and tab completion are hard to match, and you don't run a server at all.

OpenCode vs Aider (Aider Alternative)

  • Agent definitions: OpenCode has primary and subagent roles plus custom agents with their own prompts and tools. Aider is a single pair programmer with no agent system.
  • Hosting: OpenCode ships a server you can reach from a browser. Aider runs on the machine where you type.
  • Where Aider wins: It is lightweight, git-native and very mature for focused command-line edits.

OpenCode vs Continue agents (Continue Alternative)

  • Surface: Continue lives inside your IDE as an extension. OpenCode runs as a standalone server that the terminal, desktop app, IDE extension and web UI can all attach to.
  • Scoping: Both restrict tools per agent, but OpenCode's permission block and @name invocation are what stand out for us.
  • Where Continue wins: If your workflow lives in VS Code or JetBrains, Continue fits there more naturally with less setup.

How to use OpenCode Agents (the OSS AI coding agent)?

  1. Sign in to your OpenCode domain with the username opencode and the generated OPENCODE_SERVER_PASSWORD from the Variables tab.
  2. Open the service shell or the workspace so you can reach /data/home.
  3. Create the agent file /data/home/.config/opencode/agents/review.md with the frontmatter and prompt below. The file name becomes the agent name, so this one is called review.
  4. Reload the session so OpenCode picks up the new agent.
  5. Type @review and point it at a file. Because edit is set to deny, it can read and critique the file but cannot change it.
  6. Create a primary agent the same way, then switch to it with Tab.
---
description: Read-only code reviewer that flags bugs and style issues
mode: subagent
model: anthropic/claude-haiku-4-5
permission:
  edit: deny
---

You review code for bugs, unclear naming and missing error handling. Do not edit files. Report findings as a short list with file and line references.

How to self host OpenCode Agents on other VPS Services (OpenCode self hosting guide)

You can run the same server on any VPS. Set the password and working directories yourself, and go slowly.

Clone the Repository

Clone the upstream repository if you want the source and docs next to you.

git clone https://github.com/anomalyco/opencode.git
cd opencode

Install Dependencies

Install OpenCode globally, or pull the official image if you prefer containers.

npm i -g opencode-ai

Configure Environment Variables

Set a strong password first, since the server refuses to boot without one. Point HOME at a persistent directory so agent files and provider logins survive restarts.

export OPENCODE_SERVER_PASSWORD=your-long-random-password
export OPENCODE_SERVER_USERNAME=opencode
export HOME=/srv/opencode/home
export OPENCODE_WORKSPACE=/srv/opencode/workspace

Start the OpenCode Agents Application

Run the server on port 4096 and put it behind HTTPS with a reverse proxy, because basic auth over plain HTTP exposes your password.

opencode serve --hostname 0.0.0.0 --port 4096

Railway handles the HTTPS domain, the persistent volume and restarts for you, which is why the managed route saves most of this work.

Official Pricing of OpenCode Agents (OpenCode pricing)

OpenCode itself is free and open source under the MIT license, so there is no license fee for the agents, the built-in Build, Plan, General and Explore agents, or any custom agent you define in markdown or opencode.json.

OpenCode Agents cloud vs self hosted comparison (Pricing, features, costs, and more)

Self hosting OpenCode Agents means you own the server, the volume holding your agent files and provider logins, and the bill.

Monthly cost of self hosting OpenCode Agents on Railway

On Railway you pay for one container plus the volume, roughly $5-15 per month at light use.

System Requirements for Hosting OpenCode Agents on a VPS

A small VPS with a few gigabytes of RAM and enough disk for your repositories and dependency caches is a reasonable start.

Frequently Asked Questions (FAQs)

What is the difference between a primary agent and a subagent?

A primary agent is one you talk to directly, and you switch between primary agents with Tab.

Where do agent files go on this template?

Global agents live in /data/home/.config/opencode/agents, and project-specific agents go in .opencode/agents inside a repo under /data/workspace.

Can each agent use a different model?

Yes. If a subagent has no model set, it inherits the model of the agent that invoked it.

How do I stop an agent from running bash commands?

Set permission bash to deny in the agent's frontmatter, or to ask if you want to approve each command.

Can agents call other agents?

Primary agents can invoke subagents for tasks, so a build agent can hand a file search to Explore.

Do my agents survive redeploys?

Yes, as long as the agent files are in the volume-backed home directory at /data/home. Changing the image tag or redeploying the service leaves those files in place.


Template Content

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
117
View Template
NEW
Weaviate
Vector database with hybrid search and an API key-protected API

zer0person
1
View Template
Möbius v0.1 Personal AI OS
Self-hosted AI agent that builds and runs apps for you, with memory.

bento
1