Summary
An authenticated user with permission to create or modify workflows in n8n can exploit the Python Code Node to escape its sandbox and execute arbitrary code on the Python Task Runner container.
This issue is only relevant when the Python Task Runner feature is enabled, and it allows malicious workflow authors to run commands on the underlying task runner environment.
Affected context
The vulnerability occurs in n8n deployments that:
- Have the Python Task Runner feature enabled
- Allow users to add or edit workflows containing a Python Code Node
- Rely on a sandboxed execution model for Python code within the task runner container
It primarily affects multi-tenant or shared n8n instances where workflow authors are not fully trusted and are expected to be constrained by the Python sandbox.
Exploit preconditions
- Attack surface: Authenticated application users interacting with n8n's workflow editor
- Required access: Ability to create or modify workflows that include a Python Code Node
- Trigger point: Execution of a malicious workflow that causes the Python Code Node to bypass sandbox controls
- Why exploitation is possible: The sandboxing mechanism for the Python Task Runner does not fully isolate user-supplied code, allowing crafted Python input to break out of the intended restricted environment and execute arbitrary commands on the task runner container
Why this happens
The root cause lies in incomplete sandboxing of user-provided Python code executed through the Python Code Node in the task runner.
While the node is intended to run in a restricted environment, the implementation leaves pathways for code to escape those restrictions, effectively enabling arbitrary code injection and execution.
This maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), where dynamically supplied input is allowed to influence the code that runs, without sufficiently robust isolation or validation to prevent abuse.
Potential impact
- Execution of arbitrary Python code within the task runner container
- Reading or modification of data accessible to the task runner environment
- Lateral movement to other services or systems reachable from the task runner
- Disruption of workflows or denial of service on the affected task runner instance
- Use of the compromised task runner as a foothold for broader infrastructure attacks, depending on surrounding controls
General mitigation guidance
Mitigation efforts generally focus on minimizing trust in user-authored code and strengthening execution isolation:
- Restrict which users or roles are allowed to create or modify Python Code Nodes, especially in shared environments
- Treat any user-supplied code as untrusted and design task runners to run with minimal privileges and tightly scoped permissions
- Employ strong sandboxing or container hardening patterns, such as dropping unnecessary capabilities, using seccomp profiles, and isolating network access from task runners where feasible
- Provide safer, higher-level building blocks for common automation tasks so users do not need to write arbitrary Python code
- Separate high-privilege infrastructure from task runner networks to limit the blast radius if a task runner is compromised
How teams detect issues like this
High-level detection approaches may include:
- Reviewing workflow definitions for Python Code Nodes that use suspicious patterns, such as dynamic imports, system calls, or access to environment variables and file system paths
- Using static analysis or linters on embedded Python code to flag dangerous constructs or usage of sensitive modules and functions
- Implementing logging and monitoring on task runner containers to capture unusual process behavior, file access, or outbound network connections originating from Python Code Nodes
- Establishing code review or change-approval processes for workflows that incorporate arbitrary code execution nodes in multi-user environments

