Summary
A sandbox escape vulnerability in vm2 allows untrusted code to break out of the virtual machine and execute arbitrary JavaScript in the host Node.js process.
By abusing the handling of SuppressedError, an attacker can bypass vm2's isolation guarantees, turning supposedly sandboxed code execution into full remote code execution on the underlying environment.
Affected context
This issue affects applications that:
- Use vm2 to execute untrusted or partially trusted JavaScript in a sandbox
- Rely on vm2's isolation to prevent executed code from accessing the host environment
- Run Node.js versions where SuppressedError behavior can be interacted with from sandboxed code
The risk is highest in multi-tenant or plugin-style architectures where external users, extensions, or configuration can influence code executed inside vm2.
Exploit preconditions
- Attack surface: Any endpoint, plugin system, job runner, or API that feeds user-controlled or untrusted JavaScript into vm2.
- Required access: Ability to supply or influence code or data executed within the vm2 sandbox (e.g., script uploads, templates, custom rules, or user-defined functions).
- Trigger point: Execution of crafted code that interacts with SuppressedError inside the vm2 environment.
- Why exploitation is possible: vm2's handling of SuppressedError fails to fully contain or scrub host-level objects and capabilities, allowing sandboxed code to pierce the isolation boundary and reach host execution context, mapping to CWE-94 (Improper Control of Code Generation) and compounded by CWE-693 (Protection Mechanism Failure).
Why this happens
The core issue lies in vm2's incomplete enforcement of isolation around the SuppressedError mechanism.
Error handling paths are part of the security boundary in a sandbox, and in this case, SuppressedError objects or related metadata exposed more capability than intended to sandboxed code.
This constitutes a protection mechanism failure (CWE-693) because the sandbox's isolation guarantees did not hold under certain error conditions.
Once exposed to more powerful host objects or references, an attacker can craft code that leverages these primitives to construct or execute new code in the host context, aligning with CWE-94: Improper Control of Generation of Code.
In abstract terms, the sandbox trusted that error-related objects were safe to expose, but their structure allowed re-entry into the host runtime.
Potential impact
- Execution of arbitrary JavaScript in the host Node.js process, bypassing sandbox restrictions
- Access to environment variables, filesystem APIs, network APIs, or process controls available to the Node.js host
- Lateral movement within the application, including access to sensitive configuration, secrets, or backend services
- Full compromise of the application's trust boundary, enabling data exfiltration or modification of other tenants' data in multi-tenant systems
- Use of the compromised process as a stepping stone for broader infrastructure attacks, depending on host privileges
General mitigation guidance
Effective mitigation focuses on strengthening the isolation boundary and reducing trust in sandboxing as a singular control:
- Prefer defense-in-depth: treat vm2 as one layer, not the sole barrier between untrusted code and sensitive resources.
- Harden the host environment by enforcing least privilege for the Node.js process (minimal filesystem access, limited environment variables, restricted outbound network).
- Use additional OS-level sandboxing (containers, seccomp, AppArmor, SELinux, or dedicated runtime sandboxes) around processes that execute untrusted code.
- Isolate untrusted execution into separate processes or containers with narrow, well-defined communication channels instead of sharing the main application process.
- Avoid exposing powerful host objects or error types directly to sandboxed code; validate and sanitize the interface between sandbox and host.
- Establish clear boundaries for what untrusted code is allowed to do, and enforce them through configuration and architectural patterns rather than relying solely on library guarantees.
How teams detect issues like this
Organizations can approach detection and assurance by:
- Reviewing code paths where vm2 is used to:
- Identify where untrusted or user-controlled inputs are executed.
- Map the privileges of the Node.js process and what a sandbox escape would expose.
- Applying static analysis and secure code review to:
- Flag uses of sandboxing libraries as "high-value" security review targets.
- Ensure no privileged host objects, error classes, or global references are intentionally passed into the sandbox.
- Implementing runtime monitoring:
- Track unexpected filesystem access, environment variable usage, or network calls from processes that should be "restricted".
- Alert on anomalous behaviors following execution of untrusted scripts or user-generated code.
- Incorporating security testing:
- Fuzz or penetration test sandboxed execution paths, focusing on error handling, prototype chains, and exposed APIs.
- Use automated security scanners or SAST/DAST tools that highlight sandbox usage and potential breakout vectors.

