Deploy OpenCode

Open-source AI coding agent in your browser, persistent workspace

Deploy OpenCode

Just deployed

/data

Deploy and Host self hosted OpenCode (Open-Source AI Coding Agent) on Railway

This template deploys OpenCode 1.19.3 as a web AI coding agent on Railway, with a persistent workspace on a volume. The image adds git, bash, Node, Python, and SSH for cloning, building, and testing code. Password login is enforced, and free Zen models need no API key.

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

Hosting OpenCode on Railway keeps your code, prompts, and model keys on a volume you own, not in a third-party cloud. Railway handles the container lifecycle, HTTPS, health checks, and volume persistence. You bring the repo and pick a model; Railway keeps it running.

Why Deploy OpenCode, the Claude Code and Cursor alternative on Railway (Railway Free Trial)

You get the full open-source agent on your own server, not a rented Claude Code session or Cursor subscription. The Railway $5 trial covers the container; your workspace persists on the volume across redeploys. You pay for compute plus any model keys you add, no per-seat fee.

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 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 self hosting

Railway handles the image, volume, auth, and HTTPS; a raw VPS leaves those to you.

ProviderRailwayOther Provider
DigitalOceanOne-click deploy, managed volume, generated password, HTTPS.A Droplet where you run Docker, reverse proxy, TLS, storage, and auth.
AWSTurnkey setup with no IAM, VPC, or ECS work.EC2 or ECS plus networking, security groups, load balancer, and volumes.
HetznerManaged container with updates and restarts.Cheap bare VPS where you run the image, secure the UI, and keep storage mounted.

Railway is the fastest way to a private OpenCode instance.

Common Use Cases for hosted OpenCode

  • Browser-only remote dev: Leave your laptop closed and use a phone or tablet to review diffs, run tests, and merge PRs with the persistent workspace.
  • Long-running agent tasks: Start a plan-mode refactor or migration, then check back later; the container keeps working while your machine sleeps.
  • Shared team workspace: Point everyone at one hosted instance with a common /data/workspace checkout, so the team shares branch context and git history.
  • Ephemeral or locked-down machines: Use a Chromebook, iPad, or locked-down work laptop; the browser UI needs no local Node, Python, or terminal install.
  • Personal always-on agent: Keep a personal coding assistant available 24/7, so you can ask questions, run one-off scripts, or trigger builds from any device without starting a local session.

Dependencies for OpenCode Docker hosted on Railway

One container, one persistent volume, and one public port. No database, queue, or object store is needed; OpenCode keeps sessions, provider logins, and undo snapshots under /data.

Deployment Dependencies for Managed OpenCode Service (AI Coding Agent)

The service runs ghcr.io/onepush-dev/opencode:1.19.3 on port 4096. The volume mounts at /data, with /data/workspace as the working directory and /data/home as HOME. Optional provider keys stay empty, so free Zen models need no API key.

Implementation Details for OpenCode (Built on the official OpenCode 1.19.3 image)

tini runs as PID 1 and starts opencode serve --hostname 0.0.0.0 --port 4096, serving the API and embedded web UI. Redeploys keep /data/workspace and /data/home, so repos, configs, provider logins, and session history survive image changes.

How does OpenCode compare against other AI coding agents

OpenCode vs Claude Code (Claude Code Alternative)

  • Interface: OpenCode is a browser agent with a persistent workspace on your Railway server; Claude Code is a terminal-only local agent.
  • Models: OpenCode supports 75+ providers through Models.dev; Claude Code is tied to Anthropic models and billing.
  • License: OpenCode is MIT and self-hostable; Claude Code is proprietary and not self-hostable.
  • Where Claude Code wins: terminal ergonomics and Anthropic model integration are more polished.

OpenCode vs Cursor (Cursor Alternative)

  • Deployment: OpenCode runs on your own container with a shared workspace; Cursor is a desktop VS Code fork on your laptop.
  • Cost and license: OpenCode is free and open source; Cursor is proprietary with paid plans.
  • Collaboration: anyone you share the login with can open the same hosted workspace; Cursor is per-user.
  • Where Cursor wins: inline autocomplete and IDE diffing are more mature.

OpenCode vs GitHub Codespaces (GitHub Codespaces Alternative)

  • Control: OpenCode runs on Railway with your own volume for code, SSH keys and logins; Codespaces are GitHub-managed containers billed per core-hour.
  • Agent focus: OpenCode is an AI agent with plan and build modes; Codespaces is a cloud IDE with Copilot sold separately.
  • Where Codespaces wins: one-click repo launch and GitHub Actions/PR integration are smoother.

OpenCode vs Aider (Aider Alternative)

  • UI: OpenCode ships a web UI via opencode serve; Aider is terminal-only with no built-in browser server.
  • Persistence: OpenCode keeps sessions, snapshots and LSPs on /data; Aider uses your local git repo and shell.
  • License: both are open source, but OpenCode is MIT and Aider is Apache-2.0.
  • Where Aider wins: scriptability and a lighter terminal-native footprint.

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

After your Railway deploy finishes, here is your first hour.

  1. Open your Railway domain and sign in with username opencode and the generated password from the Variables tab.
  2. Add an SSH key to /data/home/.ssh or use an HTTPS token, then clone a repo into /data/workspace.
  3. Pick a model in the UI, or log in to a provider from the settings screen. Free Zen models work with no key.
  4. Chat with the agent in plan mode to discuss changes, then switch to build mode to have it edit files and run tests.
  5. The same server exposes an HTTP API, so you can also run opencode attach from a local terminal and point it at your domain.
  6. Your workspace, SSH keys, and provider logins persist across redeploys.

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

Clone the Repository

Clone the source and move into the project directory:

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

Install Dependencies

Install the CLI globally, or pull the official image:

curl -fsSL https://opencode.ai/install | bash

Docker users can run ghcr.io/anomalyco/opencode instead.

Configure Environment Variables

Set a server password and bind address before starting:

export OPENCODE_SERVER_PASSWORD=your-password
export OPENCODE_HOSTNAME=0.0.0.0

Point OPENCODE_WORKSPACE at your projects folder if you want a custom location.

Start the OpenCode Application

Launch the web server and place it behind an HTTPS reverse proxy:

opencode serve --hostname 0.0.0.0 --port 4096

Railway handles the container build, persistent volume, HTTPS domain, and generated password for you.

Official Pricing of OpenCode (OpenCode pricing)

OpenCode is free and open source under the MIT license. You pay only for the infrastructure you run it on, such as the Railway container, and for model API usage when you choose paid providers. No license fees or subscriptions apply to OpenCode itself.

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

Self hosting means you pay only for compute and model keys, not per-seat licensing. Your volume persists.

Monthly cost of self hosting OpenCode on Railway

One container on Railway runs about $5 to $15 monthly for light use, more during heavy builds. Railway's $5 trial covers early experiments. OpenCode is free and MIT licensed, no per-agent fees.

System Requirements for Hosting OpenCode on a VPS

Plan for at least 1GB RAM and 2GB disk for the volume, since the container runs Node.js, Python, git, and language servers. The image uses tini as PID 1 and expects port 4096 behind HTTPS.

Frequently Asked Questions (FAQs)

Is the web UI password protected?

Yes. The server refuses to start if OPENCODE_SERVER_PASSWORD is empty. Every path except /site.webmanifest returns 401 until you sign in with username opencode and the generated password from the Variables tab.

Does the workspace survive redeploys?

Yes. /data/workspace and /data/home live on a Railway volume. Git history, SSH keys, provider logins, sessions and undo snapshots all persist across restarts and new deploys.

Can I use my own API keys instead of free Zen models?

Yes. Fill in the optional ANTHROPIC_API_KEY, OPENAI_API_KEY, OPENROUTER_API_KEY or GEMINI_API_KEY variables, or log in to providers from the UI. Those logins persist on the volume.

How do I connect a local terminal client to this server?

Run opencode attach with your Railway domain. The same server exposes an OpenAPI HTTP API, so your local TUI talks to the hosted instance and shares its workspace.

How do I upgrade OpenCode later?

Change the image tag in the service settings and redeploy. Autoupdate is disabled with OPENCODE_DISABLE_AUTOUPDATE=true, so you control when 1.19.3 moves to a newer release.

What does it cost to run this on Railway?

The container itself typically lands around $5-15/mo depending on usage, with heavy builds costing more. Model usage is free with Zen's free models or billed by your own provider keys.


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
stella
Self-host stella with web, API, Postgres, Redis, and object storage.

Jan Kubica
7
View Template
Hermes Agent | OpenClaw Alternative with Dashboard
Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

codestorm
88