Deploy OpenCode
OpenCode AI coding agent with web UI, password login and persistent storage
Just deployed
/data
Deploy and Host OpenCode on Railway
OpenCode is an open-source, MIT-licensed AI coding agent. It reads and edits code, runs commands in a terminal and works with many model providers, including Anthropic, OpenAI, OpenRouter and its own free models. This template runs the OpenCode 2 server and web UI, so you can use the agent from any browser.
About Hosting OpenCode
Hosting OpenCode means running its server with persistent storage and keeping it behind a login, because the agent can run shell commands. This template builds the official ghcr.io/anomalyco/opencode image, pinned by version and digest, from a public GitHub repo. It keeps your workspace, sessions, provider credentials and config on one Railway volume at /data, so they survive redeploys. A small gateway adds a password sign-in page in front of OpenCode's web UI and a /healthz health check. The password is generated for each deploy, so the deploy form has nothing to fill in. Updates arrive as Railway update notices when the repo bumps the version.
Common Use Cases
- Run an AI coding agent on your repositories from a browser, on any device
- Keep long agent sessions running in the cloud instead of on your laptop
- Share one always-on coding agent server between your own machines through its API
Dependencies for OpenCode Hosting
- One Railway service built from
aalfath/opencode-railway-template(official OpenCode image, pinned by digest) - One Railway volume at
/datafor the workspace, sessions and credentials
Deployment Dependencies
- OpenCode source and docs: https://github.com/anomalyco/opencode and https://opencode.ai/docs
- Template repo, changelog and update notes: https://github.com/aalfath/opencode-railway-template
- Optional: an API key or subscription for a model provider. OpenCode's free models work without one.
Implementation Details
After the deploy finishes:
- Open the OpenCode service's Variables tab and copy
OPENCODE_PASSWORD. - Open the service's Railway domain and sign in with that password.
- Add the project folder
/data/workspace, or clone a repository into it from the built-in terminal, for examplegit clone https://github.com/YOUR-USER/YOUR-REPO /data/workspace/YOUR-REPO. - Connect your model provider under Settings → Providers, or set its usual variable (such as
ANTHROPIC_API_KEY) on the service.
The CLI and API clients use HTTP Basic auth with the user opencode and the same password, for example opencode --server https://YOUR-DOMAIN. Tools the agent needs, such as git, gh, ssh, Node.js and Python, are included. OpenCode's self-update is off: new versions reach you as Railway update notices, and the repo's CHANGELOG.md lists what changed. Your data stays on the volume when you apply an update.
Why Deploy OpenCode on Railway?
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.
Template Content

