Deploy Background Agent
Deploy and host coding agents (opencode/claude code/codex) on Railway
Just deployed
Just deployed
Just deployed
/var/lib/postgresql/data
Deploy and Host Background Agent on Railway
Background Agent is a small full-stack demo that provisions per-session "sandbox" services on Railway and routes traffic to them through a proxy.
It's inspired by Ramp's Background Agent architecture (https://builders.ramp.com/post/why-we-built-our-background-agent). You get an admin dashboard to create/retire ephemeral environments and a secure token-based link to open each sandbox in the browser.
About Hosting Background Agent
Hosting Background Agent on Railway involves deploying:
- API service (Express + TypeScript)
- Web dashboard (React + Vite)
- Postgres database to track session state.
When a user creates a session, the API uses the Railway GraphQL API to spin up a new Railway service from a sandbox container image. The API then reverse-proxies HTTP + WebSocket traffic to the correct sandbox over Railway's internal network, using a signed token to authorize access.
You'll configure two public hostnames: one for the API/dashboard and one dedicated to proxying sandbox traffic.
Common Use Cases
- Ephemeral dev/test environments per ticket, customer, or agent run
- Secure "open in browser" sandboxes for demos, support, and onboarding
- Multi-tenant workspaces where each session gets an isolated service container
Dependencies for Background Agent Hosting
Deployment Dependencies
- Railway API token + Project/Environment IDs (to create/delete sandbox services)
- GitHub personal acceses token (to clone the target repo and create branches/PRs)
Why Deploy Background Agent 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 Background Agent 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
GH_TOKEN
A github access token with contents read/write and pull requests read/write
API_PROXY_HOST
An additional public hostname for this service used to proxy requests to sandboxes(e.g. proxy.devopsdirective.com)
API_DIRECT_HOST
The primary public hostname for this service used to proxy requests to sandboxes(e.g. api.devopsdirective.com)
RAILWAY_API_TOKEN
A railway API token used to create/destroy sandbox services
RAILWAY_PROJECT_ID
The Railway project where sandboxes should be created
RAILWAY_ENVIRONMENT_ID
The Railway environment where sandboxes should be created
VITE_API_URL
Public URL of API service proxy host. This should match the value of: api.API_DIRECT_HOST
VITE_PROXY_BASE_URL
Public URL of API service. This should match the value of: api.API_PROXY_HOST

