N8N npm tasker runner set up help

Describe the problem/error/question

I am unsure on the steps to set up the task runner for Python on my current N8N envirnonment. I can’t find any documents or information on how to go about this for an npm install. I have only seen steps for docker. Could someone help provide the steps to get this set up?

What is the error message (if any)?

Python runner unavailable: Virtual environment is missing from this system

Share the output returned by the last node

Python runner unavailable: Virtual environment is missing from this system

Internal mode is intended only for debugging. For production, deploy in external mode: Task runners | n8n Docs

Information on your n8n setup

  • n8n version: 2.4.4
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: Ubuntu 22.04.5 LTS

I would recommend to consider the docker setup which has even more benefits since the release of v2 and how task runners are implemented now.

If you want to stick to npm, this should be helping you:

Set environment variables to enable the built-in task runner system for Python:
N8N_RUNNERS_ENABLED=true
N8N_RUNNERS_MODE=internal

  • Install python + tools the usual way for Ubuntu: sudo apt install python3 python3-pip python3-venv python3-dev
  • Make sure python3 or python is in your system PATH.
  • If you need specific libraries, list them in N8N_RUNNERS_PY_PACKAGES. n8n will attempt to pip install them into its managed virtual environment upon startup.

Thank you for your reply, we were looking at setting up the runners in in external mode as this is for an in production server.

Just out of curiosity, what is the reason you’re not working with a docker deployment in a production environment? I’ve managed so many services in my time as Sysadmin, which all have been migrated to docker/kubernetes when possible.

I did some research. Generally this would be possible I assume by changing the env to external and installing the task runner launcher manually:

But I only see downsides compared to a docker based setup here.

Thank you for your replies, after considering the benefits of docker I have now span up n8n with docker compose. I am now looking at setting up the task runners with Python for this new docker compose install

hi @Hopmister211 !

Since you’re now on docker-compose, the recommended setup in n8n 2.x is to run external task runners using the n8nio/runners image and connect them to the Primary n8n instance acting as the task broker. Enable runners on the Primary (N8N_RUNNERS_ENABLED=true,

N8N_RUNNERS_MODE=external), expose port 5679, and configure a shared N8N_RUNNERS_AUTH_TOKEN (must match on all services).

Then start a Python runner container pointing to http://n8n:5679 with N8N_RUNNERS_LAUNCHER=python

runners should not connect directly to workers.

Hi!

Thank you for your reply, I have now got the task runner connected successfully!

I was trying to import json and bs4 in my python but have now hit the error “Line 1: Import of standard library module ‘json’ is disallowed. Allowed stdlib modules: none Line 2: Import of external package ‘bs4’ is disallowed. Allowed external packages: none”

I have created a dockerfile and task-runners.json file to get around this but the issue is persisting and not sure where it’s going wrong.

My task-runner.json has the below config:

{
"task-runners": [
        {
                "runner-type": "python",
                "workdir": "/home/runner",
                "command": "/opt/runners/task-runner-python/.venv/bin/python",
                "health-check-server-port": "5682",
                "allowed-env": [
                        "PATH",
                        "N8N_RUNNERS_LAUNCHER_LOG_LEVEL",
                        "N8N_RUNNERS_AUTO_SHUTDOWN_TIMEOUT",
                        "N8N_RUNNERS_TASK_TIMEOUT",
                        "N8N_RUNNERS_MAX_CONCURRENCY",
                        "N8N_SENTRY_DSN",
                        "N8N_VERSION",
                        "ENVIRONMENT",
                        "DEPLOYMENT_NAME"
                ],
                "env-overrides": {
                        "PYTHONPATH": "/opt/runners/task-runner-python",
                        "N8N_RUNNERS_STDLIB_ALLOW": "*",
                        "N8N_RUNNERS_EXTERNAL_ALLOW": "bs4,beautifulsoup4"
                }
        }
 ]
}

Then my dockerfile has the below config:

FROM n8nio/runners

USER root

RUN cd /opt/runners/task-runner-python && uv pip install beautifulsoup4

COPY n8n-task-runners.json /etc/n8n-taskrunners.json

USER runner

Hi @Hopmister211

thanks for sharing the config, this helps pinpoint the issue.
Your configuration is almost correct, but the runner is not loading your custom task-runners.json file.
Because of that, the Python runner starts with the default sandbox, where no stdlib or external packages are allowed, which is why you see:

Import of standard library module ‘json’ is disallowed
Import of external package ‘bs4’ is disallowed

What’s wrong

In your Dockerfile, you are copying the config to:

/etc/n8n-taskrunners.json

But the runner only reads the config from this exact path:

/etc/n8n-task-runners.json

(missing hyphen)

Because of this filename mismatch, your N8N_RUNNERS_STDLIB_ALLOW and N8N_RUNNERS_EXTERNAL_ALLOW settings are never applied.


Fix (required)

  1. Rename the file path in the Dockerfile:
COPY n8n-task-runners.json /etc/n8n-task-runners.json
  1. Rebuild the runner image:
docker compose build n8n-runner
docker compose up -d
  1. Verify that your runner logs show it loading the custom task runner config.

If you still see issues after rebuilding, please share the runner startup logs and we can confirm the config is being picked up.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.