🚨 Libraries desallowed in n8n Code Node n8n cloud 🚨

Describe the problem/error/question

Hello everyone,

we are using n8n cloud, and recently upgraded to 1.113.3 version.

We encountered an issue with the Code node in python, when trying to import libraries, such as : re, json, bs. Here is the error message :

Security violations detected
Line 1: Import of standard library module 're' is disallowed. Allowed stdlib modules: none Line 2: Import of standard library module 'json' is disallowed. Allowed stdlib modules: none Line 3: Import of external package 'bs4' is disallowed. Allowed external packages: none

This is new, because in previous versions it worked well.

Thanks for your help,

Information on your n8n setup

  • n8n version: 1.113.3
  • Running n8n via (Docker, npm, n8n cloud, desktop app): cloud
  • Operating system: MacOS
1 Like

I encountered the same problem.

I try to modify /etc/n8n-task-runners.json like this:
“N8N_RUNNERS_STDLIB_ALLOW”: “os,sys”,
“N8N_RUNNERS_EXTERNAL_ALLOW”: “pandas,openpyxl”

but it doesn’t work.

Can you find a solution to this problem?

Hello @Jarito not yet, still not found a solution.

Thanks for answering.

I’m thinking that one solution I’ll try is to change my Python code to Javascript (using some AI). Is the only option I see at the moment.

Yes that may be a workaround, we will wait for n8n support to respond

I’ve realised that this problem is because of the new “Python (Native) (Beta)” option.
I’m running the very same code on my local machine - which has the same n8n distribution, but without this new Python option, but the old one “Python (Beta)” - and it works perfectly - as it used to do.

@Jarito In fact it’s the newer version where it’s not working, starting from version 1.113.3, where they put Python (Native) (Beta)

1 Like

Same issue here, basically it’s not allowed to import any lib, this python native is not useful for now.

1 Like

I’m getting the same error, self hosted community version 1.117.3

Version: 1.117.3 (Self-hosted, Community Edition)
Setup: Docker Compose with external task runners
Issue: Python (Native) Code node always shows “Allowed: none” regardless of environment variables

Environment variables set:

  • N8N_RUNNERS_ENABLED=true
  • N8N_RUNNERS_MODE=external
  • N8N_RUNNERS_STDLIB_ALLOW=* (also tried specific modules)
  • N8N_RUNNERS_EXTERNAL_ALLOW=* (also tried specific packages)
  • N8N_NATIVE_PYTHON_RUNNER=true

Task runners are connected and registered successfully.
Libraries are installed in custom task runner image.

Error: “Security violations detected… Allowed stdlib modules: none”

The security check in PythonTaskRunnerSandbox.ts appears to be ignoring the allowlist environment variables completely.

1 Like

I met the same problem with the icalendar module. I searched for various posts in the forum and tested their solutions out but the problem is not solved.

When running a self-hosted version of n8n, you have to mount the n8n-task-runners.json file in the docker container and then either directly change "N8N_RUNNERS_STDLIB_ALLOW": "*" in the file or either add "N8N_RUNNERS_STDLIB_ALLOW" to the allowed-env array.

Here is an example docker-compose.yml file showing the implementation for the second option:

---
services:
  n8n:
    image: n8nio/n8n:1.121.1
    restart: always
    environment:
      - N8N_RUNNERS_ENABLED=true
      - N8N_RUNNERS_MODE=external
      - N8N_RUNNERS_BROKER_LISTEN_ADDRESS=0.0.0.0
      - N8N_NATIVE_PYTHON_RUNNER=true
    ports:
      - "5678:5678"
    volumes:
      - n8n_storage:/home/node/.n8n

  runner:
    image: n8nio/runners:1.121.1
    restart: always
    env_file: n8n.env
    environment:
      - N8N_RUNNERS_TASK_BROKER_URI=http://n8n:5679
      - N8N_RUNNERS_STDLIB_ALLOW=*
    volumes:
      - ./n8n-task-runners.json:/etc/n8n-task-runners.json
    depends_on:
      - n8n

volumes:
  n8n_storage:

And the n8n-task-runners.json file:

{
	"task-runners": [
		{
			"runner-type": "javascript",
			"workdir": "/home/runner",
			"command": "/usr/local/bin/node",
			"args": [
				"--disallow-code-generation-from-strings",
				"--disable-proto=delete",
				"/opt/runners/task-runner-javascript/dist/start.js"
			],
			"health-check-server-port": "5681",
			"allowed-env": [
				"PATH",
				"GENERIC_TIMEZONE",
				"NODE_OPTIONS",
				"N8N_RUNNERS_AUTO_SHUTDOWN_TIMEOUT",
				"N8N_RUNNERS_TASK_TIMEOUT",
				"N8N_RUNNERS_MAX_CONCURRENCY",
				"N8N_SENTRY_DSN",
				"N8N_VERSION",
				"ENVIRONMENT",
				"DEPLOYMENT_NAME"
			],
			"env-overrides": {
				"NODE_FUNCTION_ALLOW_BUILTIN": "crypto",
				"NODE_FUNCTION_ALLOW_EXTERNAL": "moment",
				"N8N_RUNNERS_HEALTH_CHECK_SERVER_HOST": "0.0.0.0"
			}
		},
		{
			"runner-type": "python",
			"workdir": "/home/runner",
			"command": "/opt/runners/task-runner-python/.venv/bin/python",
			"args": ["-m", "src.main"],
			"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_RUNNERS_STDLIB_ALLOW",
				"N8N_SENTRY_DSN",
				"N8N_VERSION",
				"ENVIRONMENT",
				"DEPLOYMENT_NAME"
			],
			"env-overrides": {
				"PYTHONPATH": "/opt/runners/task-runner-python",
				"N8N_RUNNERS_EXTERNAL_ALLOW": ""
			}
		}
	]
}
5 Likes

Thank you very much merwan.

How about Cloud version ?

Thanks for your answer.

Unfortunately, I only use the self-hosted version and cannot help here

There was a significant change in how Python code node works in version 1.111.0 - a switch from Python (Pyodide - legacy) to Python (Native - beta) runtime.

For more info see the docs here Code node documentation | n8n Docs

Tried to import some modules on version 1.120.4 hosted by n8n in a Cloud and got this:

  • Worked: re , zlib, base64 and json.
  • Didn’t work: bs(ModuleNotFoundError: No module named ‘bs’)

Unfortunately I didn’t find official list of modules, which are natively supported by current Python (Native - beta) in the Cloud, so I tried running below code:

import sys
import pkgutil

modules = sorted([module.name for module in pkgutil.iter_modules()])
return [{"modules": modules}]

and got:

[
  "__future__",
  "__hello__",
  "__phello__",
  "_android_support",
  "_apple_support",
  "_collections_abc",
  "_colorize",
  "_compat_pickle",
  "_compression",
  "_ios_support",
  "_markupbase",
  "_opcode_metadata",
  "_py_abc",
  "_pydatetime",
  "_pyio",
  "_pylong",
  "_pyodide",
  "_pyrepl",
  "_sitebuiltins",
  "_strptime",
  "_sysconfigdata__emscripten_wasm32-emscripten",
  "_threading_local",
  "_weakrefset",
  "abc",
  "antigravity",
  "argparse",
  "ast",
  "asyncio",
  "base64",
  "bdb",
  "bisect",
  "bz2",
  "cProfile",
  "calendar",
  "cmd",
  "code",
  "codecs",
  "codeop",
  "collections",
  "colorsys",
  "compileall",
  "concurrent",
  "configparser",
  "contextlib",
  "contextvars",
  "copy",
  "copyreg",
  "csv",
  "ctypes",
  "dataclasses",
  "datetime",
  "decimal",
  "difflib",
  "dis",
  "doctest",
  "email",
  "encodings",
  "enum",
  "filecmp",
  "fileinput",
  "fnmatch",
  "fractions",
  "ftplib",
  "functools",
  "genericpath",
  "getopt",
  "getpass",
  "gettext",
  "glob",
  "graphlib",
  "gzip",
  "hashlib",
  "heapq",
  "hmac",
  "html",
  "http",
  "imaplib",
  "importlib",
  "inspect",
  "io",
  "ipaddress",
  "json",
  "keyword",
  "linecache",
  "locale",
  "logging",
  "mailbox",
  "mimetypes",
  "modulefinder",
  "multiprocessing",
  "netrc",
  "ntpath",
  "nturl2path",
  "numbers",
  "opcode",
  "operator",
  "optparse",
  "os",
  "pathlib",
  "pdb",
  "pickle",
  "pickletools",
  "pkgutil",
  "platform",
  "plistlib",
  "poplib",
  "posixpath",
  "pprint",
  "profile",
  "pstats",
  "pty",
  "py_compile",
  "pyclbr",
  "pydoc",
  "pyodide",
  "queue",
  "quopri",
  "random",
  "re",
  "reprlib",
  "rlcompleter",
  "runpy",
  "sched",
  "secrets",
  "selectors",
  "shelve",
  "shlex",
  "shutil",
  "signal",
  "site",
  "smtplib",
  "socket",
  "socketserver",
  "sre_compile",
  "sre_constants",
  "sre_parse",
  "stat",
  "statistics",
  "string",
  "stringprep",
  "struct",
  "subprocess",
  "symtable",
  "sysconfig",
  "tabnanny",
  "tarfile",
  "tempfile",
  "textwrap",
  "this",
  "threading",
  "timeit",
  "token",
  "tokenize",
  "tomllib",
  "trace",
  "traceback",
  "tracemalloc",
  "tty",
  "types",
  "typing",
  "unittest",
  "urllib",
  "uuid",
  "warnings",
  "wave",
  "weakref",
  "webbrowser",
  "wsgiref",
  "xml",
  "xmlrpc",
  "zipapp",
  "zipfile",
  "zipimport",
  "zoneinfo"
]

However this does not list all the modules for some reason. For example zlib is not there, but can be imported.

It work for me

does this work for version 2.0.2?

it looks like all imports were disabled on cloud version starting v1.123 - see Python Native Node: Import of standard library modules fails on 1.123 (regression) · Issue #23072 · n8n-io/n8n · GitHub

Did anyone ever find a solution to this?

works for me! tks