Summary
An input validation flaw in n8n's Python Code Node allows authenticated workflow designers to escape the intended sandbox and run arbitrary code on the task runner container.
When a user can create or modify workflows containing Python code, insufficient validation and isolation controls can turn business automation workloads into an application-level remote code execution vector.
Affected context
This vulnerability appears in n8n installations that expose the Python Code Node to authenticated users who can create or modify workflows.
It is relevant where task runners execute user-supplied Python code under the assumption of sandboxed isolation, but the enforcement of that isolation and validation of untrusted code is incomplete or flawed.
The risk is higher in multi-tenant or shared environments where workflow authorship is delegated to non-admin users and task runner containers have access to sensitive systems or data.
Exploit preconditions
- Attack surface: n8n workflow editor and execution engine, via the Python Code Node.
- Required access: Authenticated access with permissions to create or modify workflows that include Python code.
- Trigger point: Execution of a workflow containing crafted Python Code Node content on the task runner.
- Why exploitation is possible: The sandbox and validation layer around user-provided Python code is insufficiently strict, allowing code patterns that bypass isolation controls and execute with the container's runtime privileges.
Why this happens
The underlying issue maps to CWE-20 (Improper Input Validation), where the system assumes that user-supplied Python code, once placed in a "sandboxed" node, will be safely constrained.
In practice, the sandbox and validation mechanisms do not adequately restrict available APIs, execution context, or escape vectors, letting crafted code interact with the broader runtime.
The insecure pattern is treating user-authored automation logic as trusted, without enforcing robust isolation boundaries or strong validation of what that code can do inside the execution environment.
Potential impact
- Authenticated users may execute arbitrary OS-level commands in the task runner container.
- Attackers could access secrets, environment variables, or credentials available in the runner.
- Workflows can be abused to pivot into connected services, data stores, or internal APIs.
- Malicious automation may modify or exfiltrate workflow data, logs, or configuration.
- In some deployments, compromise of the task runner could facilitate further lateral movement.
General mitigation guidance
Mitigation generally focuses on reinforcing the boundary between user-supplied workflow code and the underlying execution environment.
Common patterns include:
- Restricting or disabling generic code-execution nodes (such as Python Code Nodes) in multi-tenant or untrusted user contexts.
- Applying strict input validation and policy controls to workflow code, limiting available libraries, system calls, and I/O.
- Running task runners with minimal OS-level privileges and isolating them from sensitive networks, secrets, and file systems.
- Introducing defense-in-depth sandboxing (containers, seccomp, AppArmor, or language-level restrictions) around user-provided code.
- Establishing clear trust boundaries so that only highly trusted operators can define or modify nodes that execute arbitrary code.
How teams detect issues like this
Effective detection blends configuration review, workflow inspection, and code-level analysis:
- Use static analysis or linting on workflow definitions to flag Python Code Nodes or patterns that access system-level resources.
- Implement review workflows where changes to code-execution nodes require approval from security or platform engineers.
- Monitor task runner containers for anomalous process creation, filesystem access, or outbound network connections.
- Apply policy-based controls (e.g., admission checks) that prevent deployment of workflows using disallowed node types or constructs.
- Consider automated security tooling that can scan workflow repositories and configuration for unsafe code-execution capabilities.

