Summary
vm2's NodeVM sandbox allows nested virtual machines to bypass require() restrictions when nesting: true is enabled.
Untrusted code running in such a NodeVM can load vm2 itself, spawn a new inner NodeVM with unrestricted require settings, and ultimately execute arbitrary OS commands on the host.
Affected context
This vulnerability affects Node.js applications that:
- Use vm2's
NodeVMto execute untrusted or semi-trusted JavaScript - Enable
nesting: truein the NodeVM configuration - Rely on
requirerestrictions (includingrequire: false) to enforce sandbox boundaries
The issue appears when sandboxed code can obtain access to the vm2 module inside the sandbox, construct new VMs, and escape the original security policy.
Exploit preconditions
- Attack surface: Any API, plugin system, or feature that evaluates user-supplied code using vm2's
NodeVMwithnesting: true. - Required access: Ability to supply JavaScript that is executed inside the vulnerable NodeVM (e.g., user scripts, templates, expressions, or configuration-defined code).
- Trigger point: Execution of attacker-controlled code within the NodeVM that calls
require('vm2')and creates a new, less-restricted NodeVM instance. - Why exploitation is possible: The nested NodeVM bypasses the outer VM's
requireconfiguration, allowing construction of an inner VM with fullrequireaccess, including modules that perform OS-level operations.
Why this happens
The root cause is a broken access control boundary in vm2's handling of nested NodeVM instances.
When nesting: true is set, the sandboxed environment can unconditionally call require('vm2'), regardless of the outer VM's require configuration.
This violates the expectation that disabling or restricting require in the outer VM prevents access to sensitive modules.
Conceptually, this aligns with CWE-284: Improper Access Control, where security policies are inconsistently enforced across nested or delegated components, allowing a bypass of intended restrictions.
Potential impact
- Execution of arbitrary OS commands on the host running the Node.js process
- Complete compromise of the application process and its data
- Lateral movement within the hosting environment, depending on process privileges
- Exfiltration or tampering of sensitive data handled by the application
- Use of the compromised host as a platform for further attacks
General mitigation guidance
Effective mitigation focuses on reinforcing sandbox boundaries and limiting trust in nested execution environments:
- Avoid enabling
nesting: truefor any NodeVM that executes untrusted or user-supplied code, unless strict additional controls exist. - Treat sandbox escape as a realistic failure mode and run sandboxed workloads under separate, least-privilege OS identities or containers.
- Isolate the code-execution service from critical infrastructure and sensitive data; design for blast-radius reduction.
- Apply defense-in-depth by combining vm2 with external controls such as process-level seccomp, container sandboxes, and strict filesystem/network permissions.
- Regularly review and harden sandbox configuration defaults, favoring deny-by-default for capabilities like
require, networking, and filesystem access.
How teams detect issues like this
To detect this class of issue, organizations can:
- Use static analysis or code search to identify creation of
NodeVMinstances withnesting: true, especially when combined with untrusted input. - During code review, flag any pattern where require restrictions are assumed to be sufficient isolation for untrusted code, and verify nested VM access.
- Implement centralized security wrappers or factory functions for vm2 usage, enforcing safe defaults and disallowing direct creation of nested VMs.
- Employ runtime monitoring and logging for sandboxed code execution, including alerts for unexpected module loads or OS-level command execution originating from sandboxed contexts.

