|Docs

railway run

Execute a command locally with environment variables from your Railway service injected.

Usage

railway run [OPTIONS] <COMMAND> [ARGS...]

Aliases

  • railway local

Options

FlagDescription
-s, --service <SERVICE>Service to pull variables from (defaults to linked service)
-e, --environment <ENV>Environment to pull variables from (defaults to linked environment)
-p, --project <ID>Project ID to use (defaults to linked project)
--no-localSkip local develop overrides
-v, --verboseShow verbose domain replacement info

Examples

Run a Node.js app

railway run npm start

Run a Python script

railway run python main.py

Run with specific service variables

railway run --service backend npm start

Run database migrations

railway run npx prisma migrate deploy

Access a repl

railway run rails console
railway run python

How it works

  1. Fetches environment variables from the specified Railway service
  2. Injects them into the command's environment
  3. Executes the command

This is useful for:

  • Running your app locally with production/staging variables
  • Running database migrations
  • Accessing REPLs with the correct environment

Exit codes

The command exits with the same code as the executed command.