Index of every page on this site: llms.txt
All skills
Run it yourself

Define and manage Railway projects with Infrastructure as Code in .railway/railway.ts. Use when authoring or editing Railway IaC files, running railway config init/pull/plan/apply, declaring services, databases, volumes, buckets, domains, or env vars in code, setting up multi-repo partials, or wiring railway config into CI. Triggers on "railway iac", "railway.ts", "infrastructure as code railway", "railway config plan", "define railway services in code". For migrating railway.json/railway.toml, use the railway-iac-migration skill instead.

Use this Skill: https://skilld.dev/gh/sivarampg/railway-iac-skill/railway-iac

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈139 tokens for metadata: the name and description. ≈1.6k when used: this file. ≈3k more on demand in 2 files.

Description uses 7.0% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈558 characters, or 7.0%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Railway Infrastructure as Code

Define a Railway project's services, databases, volumes, buckets, custom domains, environment variables, replicas, and canvas groups in one authoring file. The Railway CLI evaluates the file against the linked environment, prints a diff, and applies only after confirmation.

.railway/railway.ts   # generally available (the documented default)
.railway/railway.py   # beta
.railway/railway.go   # beta

Keep exactly one authoring file, never two languages in .railway/. This skill documents TypeScript (import { ... } from "railway/iac"); Python and Go mirror the same graph.

Key mental model: Railway does not read .railway/ during deploys. railway config plan / apply run wherever you run them (locally or in CI) and reconcile the file with the live environment. Deleting a resource from the file deletes it on apply (within your ownership scope; see partials).

Step 1: Prerequisites

# Railway CLI, then auth + link this directory to a project/environment
railway login
railway link

# TypeScript authoring package (use the repo's package manager)
npm install railway
# Python (beta): pip install railway-sdk
# Go (beta): go get github.com/railwayapp/railway-go-sdk@v0.2.0

If the directory isn't linked, railway config plan / apply / pull prompt for a project and environment. RAILWAY_TOKEN (an environment-scoped project token) also works for CI.

Step 2: Get an authoring file

Pick one:

railway config init    # new project; scaffolds .railway/railway.ts + .railway/README.md
railway config pull    # existing project; imports live config into the authoring file

railway config pull generates human-editable code: keeps names, omits platform defaults and generated Railway domains, and renders existing variable values as preserve() so secrets stay on Railway. Never pass --include-variables casually. It decrypts non-sealed variables (including secrets) into source.

After a pull, verify the import is clean:

railway config plan
# expect: "Your Railway configuration is already up to date."

Step 3: Author

import { defineRailway, project, service } from "railway/iac";

export default defineRailway((ctx) => {
  const web = service("web", {
    build: "pnpm build",
    start: "pnpm start",
    healthcheck: "/health",
    replicas: ctx.environment === "production" ? 3 : 1,
  });

  return project("my-project", { resources: [web] });
});

Full DSL: sources (github, image), env / preserve() / ctx.shared, postgres/redis/mysql/mongo, volume + volumeMounts, bucket, domains, group, and every ctx field: references/dsl-reference.md.

Step 4: Plan, review, apply

railway config plan      # read-only diff; secrets shown as «hidden»
railway config apply     # fresh plan + interactive confirm

Useful flags:

railway config plan --json                  # machine-readable
railway config plan --show-values           # reveal variable values (careful with secrets)
railway config plan --detailed-exit-code    # 0 = clean, 2 = changes pending (CI drift gate)
railway config apply --yes                  # non-interactive

# Pin a reviewed plan for later/CI apply (recommended over re-planning on merge)
railway config plan --out railway-plan.json
railway config apply --plan railway-plan.json --yes --confirm-destructive

plan and apply find the nearest .railway/railway.{ts,py,go} walking up from the current directory; --file overrides.

Step 5 (optional): Multi-repo partials

One repo holding every service: one file, no partial export. Services split across repos: each repo's file exports export const partial = "<name>" and manages only what it declares. The CLI records per-resource ownership; a partial can only delete resources it owns.

Partials commands (partials list, transfer, release) and the GitHub Actions recipe (railwayapp/config@v1 plan-on-PR / apply-on-merge): references/workflows.md.

Safety rules: read before applying

  • Destructive changes are marked in the plan. Deleting services, variables, volumes, or buckets requires --confirm-destructive in non-interactive runs; a stray --yes cannot remove resources. Review marked lines carefully.
  • A whole-project apply deletes resources omitted from the file. In a partial, only owned-and-omitted resources are deleted.
  • Never inline secrets. Use preserve() for values that should stay on Railway, ctx.shared.NAME for existing shared variables. Plan output redacts values by default; keep it that way in CI logs.
  • Stale-plan protection exists. Respect it. Apply commits against the environment state it just read. If the environment drifted (concurrent apply, dashboard edit), apply is rejected; re-plan rather than forcing.
  • Services still managed by railway.json/railway.toml block plan. The error names the offending service. Migrate it first with the railway-iac-migration skill.
  • tracing is not yet in the SDKs. service() drops a tracing block you write, so plan may propose removing tracing from a traced service. Don't apply a plan that removes a tracing block you didn't remove yourself; set tracing from the Traces page or railway trace until SDK support lands.
  • Bucket regions are immutable. Create a new bucket + copy data to move regions.
  • Volume lifecycle is conservative by design. Shrinking sizeMB, detaching a mounted volume, or deleting a volume is destructive.
  • railway config pull does not overwrite blindly. Use --force intentionally when re-importing over a hand-edited file.

Troubleshooting

Symptom Fix
plan fails: service managed by config file Service still reads railway.json/railway.toml. Migrate it (see railway-iac-migration skill)
plan fails: file without partial in environment that has named partials Add export const partial = "<name>", or release all named ownership first
Cannot manage service "x": already managed by partial "y" Move the declaration to the owning repo, or railway config partials transfer
Apply rejected as stale Environment changed since plan. Run railway config plan again
railway/iac import not found npm install railway in the repo that holds .railway/

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts1mo3 checks · Risk SAFE
  • Gen Agent Trust Hub1mo

    The skill provides a secure and well-documented set of instructions for managing Railway Infrastructure as Code. It leverages official SDKs and GitHub Actions from the Railway organization and emphasizes security best practices, such as using the preserve() function to manage secrets and warning users about destructive operations and sensitive data exposure during configuration imports.

  • Socket1mo

    No alerts

  • Snyk1mo

    Risk: LOW · No issues

Signed by skilld at ba3f473. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 2 months ago
metadata
{
  "version": "1.0.0"
}

README badge

README badge for sivarampg/railway-iac-skill/railway-iac