Run n8n task runners on host (systemd) with n8n in Docker

Run n8n task runners on Ubuntu host via systemd while keeping n8n in Docker Compose, enabling Python in Code nodes securely.

Architecture Overview

n8n Docker exposes Task Broker on 127.0.0.1:5679. Host task-runner-launcher connects to it, spawns JS/Python runners. Ports: 5678 (UI), 5679 (broker), 5680 (launcher health), 5681 (JS), 5682 (Python).

Prerequisites

sudo apt update && sudo apt install -y git curl ca-certificates build-essential docker-compose-plugin nodejs

Install uv:

curl -LsSf https://astral.sh/uv/install.sh | sh

Download launcher:

wget -O /usr/local/bin/task-runner-launcher https://github.com/n8n-io/task-runner-launcher/releases/latest/download/task-runner-launcher-linux-amd64 && chmod +x /usr/local/bin/task-runner-launcher

n8n Docker Compose

services:
  n8n:
    image: n8nio/n8n
    ports:
      - "127.0.0.1:5678:5678"
      - "127.0.0.1:5679:5679"
    environment:
      - N8N_RUNNERS_ENABLED=true
      - N8N_RUNNERS_MODE=external
      - N8N_RUNNERS_AUTH_TOKEN=TESTn8n123
      - N8N_RUNNERS_BROKER_LISTEN_ADDRESS=0.0.0.0
      - N8N_RUNNERS_BROKER_PORT=5679
docker compose up -d

Setup Runner User and Code

sudo useradd -m -s /bin/bash runner
sudo mkdir -p /home/runner/runners
sudo chown -R runner:runner /home/runner/runners
sudo -u runner bash -lc 'cd /home/runner/runners && git clone https://github.com/n8n-io/n8n.git n8n-src'

Python:

sudo -u runner bash -lc 'cp -a /home/runner/runners/n8n-src/packages/@n8n/task-runner-python /home/runner/runners/task-runner-python && cd /home/runner/runners/task-runner-python && uv sync'

Runners Config and Systemd

Create /etc/n8n-task-runners.json with JS/Python configs (see context for full JSON with allowlists).
Systemd /etc/systemd/system/n8n-runner.service:

[Unit]
Description=N8N Task Runner Launcher
After=network.target
[Service]
Type=simple
User=runner
ExecStart=/usr/local/bin/task-runner-launcher javascript python
Environment=N8N_RUNNERS_CONFIG_PATH=/etc/n8n-task-runners.json
Environment=N8N_RUNNERS_AUTH_TOKEN=TESTn8n123
Environment=N8N_RUNNERS_TASK_BROKER_URI=http://127.0.0.1:5679
Environment=N8N_RUNNERS_LAUNCHER_HEALTH_CHECK_PORT=5680
Restart=always
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload && sudo systemctl enable --now n8n-runner
journalctl -u n8n-runner -f

Verify: curl http://localhost:5680/healthz (200 OK).

Quick Setup: Download and run the automated setup.sh script: setup.sh (Co-authored by <ai>).

References



Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *