---
title: "Deploy N8N"
description: "n8n + Postgres with external task runners."
category: "Automation"
url: https://railway.com/deploy/n8n-8
---

# Deploy N8N

n8n + Postgres with external task runners.

**[Deploy N8N on Railway](https://railway.com/template/n8n-8)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/n8n-8/manifest.json

- **Creator:** darseen
- **Category:** Automation

## Template content

### Postgres https://devicons.railway.com/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18

### n8n https://devicons.railway.com/i/n8n.svg

- **Image:** n8nio/n8n:2.40.7
- **Start command:** `sh -c 'test "$(stat -c %U /home/node/.n8n)" = node || chown -R node:node /home/node/.n8n; export HOME=/home/node; exec su -p -s /bin/sh node -c "exec /sbin/tini -- /docker-entrypoint.sh"'`
- **Health check:** /healthz/readiness
- **Public domain:** Yes

### n8n-runners https://devicons.railway.com/i/n8n.svg

- **Image:** n8nio/runners:2.40.7
- **Start command:** `sh -c 'node <<"JS"
const fs = require("fs");
const cfg = JSON.parse(fs.readFileSync("/etc/n8n-task-runners.json", "utf8"));
const keys = {
  javascript: ["NODE_FUNCTION_ALLOW_BUILTIN", "NODE_FUNCTION_ALLOW_EXTERNAL"],
  python: ["N8N_RUNNERS_STDLIB_ALLOW", "N8N_RUNNERS_EXTERNAL_ALLOW"],
};
for (const runner of cfg["task-runners"]) {
  for (const key of keys[runner["runner-type"]] || []) {
    if (key in process.env) runner["env-overrides"][key] = process.env[key];
  }
}
fs.writeFileSync(process.env.N8N_RUNNERS_CONFIG_PATH, JSON.stringify(cfg, null, 2));
JS
exec /sbin/tini -- /usr/local/bin/task-runner-launcher javascript python'`
- **Health check:** /healthz

## Documentation

# Deploy and Host N8N on Railway

**This variant: n8n with external task runners, so Python Code nodes work.** n8n and Postgres plus n8n's official runners sidecar, which executes JavaScript and Python Code nodes in a separate container. n8n is an open-source workflow automation platform with 400+ integrations, AI agent nodes and a visual editor: a self-hosted alternative to Zapier and Make with no per-execution fees.

## About Hosting N8N

Since n8n 2.0, the Python Code node only runs on task runners in external mode, which the standard single-container setup does not have. This template deploys three services:

- `n8n`: the editor, API, triggers and executions, with a volume at `/home/node/.n8n`. It hosts the task broker on port 5679 of the private network.
- `n8n-runners`: the `n8nio/runners` image. Its launcher connects to the broker and starts JavaScript and Python runners on demand.
- `Postgres`: workflows, credentials and execution history.

Both n8n images are pinned to 2.40.7. The first boot runs n8n's database migrations, which takes about a minute. Then open the public URL and **create the owner account right away**: the first visitor to an unclaimed instance becomes its owner.

## Common Use Cases

- Data cleanup and transformation in Python Code nodes
- Keep user-written code out of the n8n process, which holds your credentials and encryption key
- Teams where several people write Code nodes and you want n8n's recommended isolation

## Dependencies for N8N Hosting

- Nothing to bring. Every secret (Postgres password, n8n encryption key, runner auth token) is generated at deploy time.
- Optional: API keys for the services your workflows connect to, added later as n8n credentials.

### Deployment Dependencies

- n8n: https://github.com/n8n-io/n8n
- Images: https://hub.docker.com/r/n8nio/n8n and https://hub.docker.com/r/n8nio/runners
- Task runner docs: https://docs.n8n.io/hosting/configuration/task-runners/

### Implementation Details 

- **What Code nodes may import** is set on `n8n-runners`, and the defaults are deliberately narrow:
  - `N8N_RUNNERS_STDLIB_ALLOW`: Python standard library modules. Ships with data-processing modules only (`json`, `re`, `datetime`, `math`, `statistics`, `collections`, `hashlib`, `csv` and similar), not `os`, `sys`, `subprocess` or `socket`. Set it to `*` to allow all.
  - `NODE_FUNCTION_ALLOW_BUILTIN` (`crypto`) and `NODE_FUNCTION_ALLOW_EXTERNAL` (`moment`): the JavaScript equivalents.
  - `N8N_RUNNERS_EXTERNAL_ALLOW`: third-party Python packages. The stock image has none; add them by extending `n8nio/runners` as described in n8n's docs.
- **How the allowlists apply.** The launcher only reads them from its JSON config, so the start command writes a copy of the image's `/etc/n8n-task-runners.json` with these four variables applied and points `N8N_RUNNERS_CONFIG_PATH` at it.
- **Shared secret.** `N8N_RUNNERS_AUTH_TOKEN` is generated on `n8n` and referenced from `n8n-runners`, and the broker listens on the private network only.
- **Other N8N variants.** This creator also publishes n8n with Postgres, queue mode with workers, workers plus webhook processors, and a single-service SQLite version.
- **Back up `N8N_ENCRYPTION_KEY`.** Without it, stored credentials cannot be decrypted.
- **Custom domain.** After adding one, set `N8N_EDITOR_BASE_URL` and `N8N_WEBHOOK_URL` on `n8n` to `https://your-domain`.
- **Upgrading.** `n8nio/runners` must match the `n8nio/n8n` version exactly. Change both tags together and redeploy both services.

## Why Deploy N8N 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 N8N 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.



## Similar templates

- [N8N Main + Worker](https://railway.com/deploy/n8n-main-worker) — Deploy and Host N8N with Inactive worker.
- [Evolution API with n8n](https://railway.com/deploy/evolution-api-with-n8n) — Automate WhatsApp workflows with Evolution API, n8n, and Postgres.
- [Postgres Backup](https://railway.com/deploy/postgres-s3-backups) — Cron-based PostgreSQL backup to bucket storage

Open this page in a browser: https://railway.com/deploy/n8n-8
