Environment
-
n8n v2.23.4
-
Self-hosted on Hostinger VPS (Ubuntu 24)
-
Docker Compose deployment
-
Official
n8nio/n8nimage
Context
I wanted to use the Python Code node in n8n to process data with pandas. What looked like a 10-minute setup turned into 3 hours of cascading debugging. Here are the 3 errors in the exact order they appear, and how to fix each one.
ERROR 1 — Python code execution is not enabled
Exact message:
Python code execution is not enabled
Cause: n8n doesn’t enable Python runners by default. You need two environment variables in your docker-compose.yml:
environment:
- N8N_RUNNERS_ENABLED=true
- N8N_RUNNERS_MODE=external
Restart the container. This error goes away — and you immediately hit the next one.
ERROR 2 — Security violations detected (all imports blocked)
Exact message:
Security violations detected
Line 1: Import of standard library module 'sys' is disallowed. Allowed stdlib modules: none
Line 2: Import of external package 'pandas' is disallowed. Allowed external packages: none
Cause: This is the sneaky one. The official n8nio/n8n image ships with a hardcoded /etc/n8n-task-runners.json that silently overrides N8N_RUNNERS_STDLIB_ALLOW and N8N_RUNNERS_EXTERNAL_ALLOW — even if you set them in your docker-compose.yml. Result: zero imports allowed, not even sys.
Fix: build a custom Docker image that corrects this file and pre-installs your packages.
Create a Dockerfile:
FROM n8nio/n8n:latest
USER root
# Fix the Python runner config file
RUN echo '{ \
"runners": [{ \
"runnerType": "python", \
"maxConcurrency": 5, \
"python": { \
"allowedModules": "*", \
"allowedExternalModules": "*" \
} \
}] \
}' > /etc/n8n-task-runners.json
# Install required Python packages into the runner venv
RUN cd /opt/runners/task-runner-python && \
.venv/bin/pip install pandas numpy requests
USER node
In your docker-compose.yml, replace the image with your local build:
services:
n8n:
build: .
# image: n8nio/n8n ← comment this out
Rebuild and restart. Imports work — and you hit the next error.
ERROR 3 — No module named ‘pandas’
Exact message:
No module named 'pandas'
Cause: Even if pandas is installed somewhere in the container, the Python runner runs inside its own isolated virtualenv: /opt/runners/task-runner-python/.venv/. Packages installed outside this venv are invisible to it.
Fix: the pip install step in the Dockerfile above handles this — but you must target the runner’s venv explicitly (cd /opt/runners/task-runner-python && .venv/bin/pip install ...).
If you previously ran a plain pip install pandas inside the container without going through that venv, that’s why it didn’t work.
Final result
With this custom image, this runs cleanly in the Python Code node:
import pandas as pd
import sys
df = pd.DataFrame({"a": [1, 2, 3]})
print(df)
print(sys.version)
The takeaway
The official n8n image is not ready out of the box for Python in self-hosted setups. The /etc/n8n-task-runners.json file takes priority over your environment variables — and this is not clearly documented anywhere. A custom image is the only clean fix.
Hope this saves someone else 3 hours.