Summary
A JavaScript task runner sandbox escape in n8n allows an authenticated user with Code node access to bypass intended isolation through prototype pollution. Successful exploitation may enable arbitrary command execution in the runner container and can affect other tenants sharing the same runner.
Affected context
The vulnerability occurs in n8n deployments where authenticated users can create or run JavaScript Code nodes. It is particularly relevant to shared task runners whose prototype-freezing protections do not cover internal module constructors. On deployments without task runners, JavaScript may execute in the main n8n process, which could increase the scope of compromise.
Exploit preconditions
- Attack surface: JavaScript Code node execution
- Required access: An authenticated account with permission to use Code nodes
- Trigger point: Processing attacker-controlled JavaScript within the task runner
- Why exploitation is possible: Prototype protections omit certain internal module constructors, allowing prototype pollution to alter process-wide behavior and escape the intended VM boundary
Why this happens
The underlying bug is an incomplete JavaScript sandbox hardening routine. Although functions exposed through globalThis are protected, internal module constructors such as EventEmitter remain mutable and can be reached through prototype relationships. This permits prototype pollution to modify shared runtime behavior and maps to CWE-94: Improper Control of Generation of Code, because attacker-controlled input can influence execution beyond the intended restricted code environment.
Potential impact
- Arbitrary commands may execute within the task runner container
- The runner process could be compromised
- Other tenants' Code node executions may be affected through process-wide prototype corruption
- Secrets or data available to the runner could be exposed
- On deployments executing Code nodes in the main process, the n8n application may be at greater risk
General mitigation guidance
Mitigation generally focuses on using a thoroughly isolated execution architecture and preventing untrusted Code node users from reaching mutable runtime internals.
Common defensive patterns include:
- Use a maintained, strongly restricted JavaScript execution boundary with comprehensive prototype hardening
- Prefer process or container isolation over relying solely on an in-process VM sandbox
- Restrict Code node access to trusted users and apply least-privilege authorization
- Avoid sharing runners across tenants when prototype or process state can persist between executions
- Limit runner access to credentials, filesystems, networks, and administrative interfaces
- Keep task runner and sandbox components maintained through the organization's standard security update process
- Apply resource, network, and filesystem policies that reduce the consequences of a sandbox escape
How teams detect issues like this
Detection can combine code review, runtime monitoring, and policy enforcement:
- Review sandbox code for incomplete freezing of prototypes, constructors, globals, and module-provided objects
- Use static analysis to identify exposed constructors, prototype mutation, dynamic property assignment, and unsafe VM boundaries
- Monitor Code node executions for unexpected process APIs, child-process activity, filesystem changes, or outbound connections
- Alert on prototype modifications involving shared built-in objects or internal module types
- Enforce authorization policies that restrict Code node creation and execution to approved roles
- Use automated security review tools to identify sandbox escape and code-generation patterns during development

