Skip to content
CLI tool · Cloud & deploy

Railway CLI for AI agents

The Railway CLI for AI agents: link projects, check status, read logs and variables, and run commands with service env vars, plus safe deploy rules.

railwayby RailwayOfficial MCP option
What it is

What Railway CLI does for an agent

The Railway CLI is Railway's official tool for working with projects from the terminal. It links a directory to a project and service, shows status and logs, manages variables, deploys with railway up, and runs local commands with the service's environment injected.

railway run is handy for agents: it runs a script, such as a migration check, with the same variables the deployed service sees, without copying secrets into files.

Official site: railway.com

Install

Install Railway CLI

The install commands from the official docs. Check it worked with railway --version.

Homebrew
brew install railway
npm (global)
npm install -g @railway/cli
Auth

Signing in Railway CLI for an agent

A human signs in with railway login. For CI and agents, Railway documents a project token in RAILWAY_TOKEN and an account or team token in RAILWAY_API_TOKEN.

Check the sign-in (read-only)
railway whoami
Interactive sign-in (human)
railway login
Link this directory to a project
railway link

Environment variables: RAILWAY_TOKEN, RAILWAY_API_TOKEN. Set them in the agent's environment; never paste values into prompts or commit them.

Common agent tasks

What agents use Railway CLI for

Example commands with placeholder names. Swap in your own project, app, or file names.

  1. Show the linked project and service

    railway
    railway status
  2. Read deployment logs

    railway
    railway logs

    May keep streaming; run it with a timeout.

  3. List service variables

    railway
    railway variables

    Prints secret values. Do not echo them into chat or files.

  4. Run a local command with service env vars

    railway
    railway run npm run db:check
Safety

Safety rules for agents

Safe to run without asking

  • railway whoami
  • railway status
  • railway logs

Ask a human first

  • railway up
  • railway down
  • railway variables --set KEY=value
  • railway run <a command that writes data>
  • railway up deploys the current directory; leave it to a human or CI unless deploys were explicitly delegated.
  • railway variables and railway run expose production secrets. Never print or store their values.
  • Prefer a project token scoped to one environment over an account token.
Agent instructions

AGENTS.md or CLAUDE.md snippet

Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.

AGENTS.md
## Railway CLI (railway)

Use `railway` for inspecting and deploying services on Railway and running commands with their environment variables.

- Check it is installed with `railway --version`. If it is missing, ask before installing it.
- Auth: a human signs railway in. Check with `railway whoami`; if it fails, stop and ask. Never run the login flow yourself, and never print tokens (RAILWAY_TOKEN, RAILWAY_API_TOKEN).
- Run without asking (read-only): `railway whoami`, `railway status`, `railway logs`.
- Ask a human first (changes or deletes things): `railway up`, `railway down`, `railway variables --set KEY=value`, `railway run <a command that writes data>`.
- railway up deploys the current directory; leave it to a human or CI unless deploys were explicitly delegated.
- railway variables and railway run expose production secrets. Never print or store their values.
- Prefer a project token scoped to one environment over an account token.
- Prefer JSON output where the command supports it, and keep output short.
CLI or MCP server?

Railway CLI or an MCP server?

An official MCP option exists. Railway publishes an official MCP server for creating projects, deploying, and reading logs and variables. The CLI is simpler inside a linked repository; the MCP server suits chat clients without a shell.

Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.

Same category
All Cloud & deploy tools
FAQ

Railway CLI questions

How do I install Railway CLI?

Homebrew: brew install railway. Other official options: npm (global). Check the install with railway --version, and see the Railway docs for other platforms.

How does an AI agent authenticate Railway CLI?

A human signs in with railway login. For CI and agents, Railway documents a project token in RAILWAY_TOKEN and an account or team token in RAILWAY_API_TOKEN. The agent can check the sign-in with railway whoami and should stop and ask if it fails.

Which Railway CLI commands are safe for an agent to run?

Commands that only read state are safe to run without asking: railway whoami; railway status; railway logs. Ask a human before anything that changes or deletes something: railway up; railway down; railway variables --set KEY=value; railway run <a command that writes data>.

Is there an MCP server for Railway CLI?

Railway publishes an official MCP server for creating projects, deploying, and reading logs and variables. The CLI is simpler inside a linked repository; the MCP server suits chat clients without a shell.