Summary
vm2, a popular sandboxing library for Node.js, allowed sandboxed code to obtain a reference to the host Object before version 3.11.0.
With access to the host Object, attackers can bypass isolation, inject arbitrary JavaScript, and potentially execute code on the host environment whenever untrusted code is run inside vm2.
Affected context
This vulnerability affects applications that:
- Use vm2 as a sandbox to execute untrusted or semi-trusted JavaScript
- Rely on vm2 isolation guarantees to protect the host Node.js process
- Expose host utilities or objects to the sandboxed code, directly or indirectly
The risk is most pronounced in multi-tenant systems, online code runners, plugin architectures, or any environment where user-controlled code is evaluated in vm2.
Exploit preconditions
- Attack surface: Any vm2 sandbox where untrusted or user-controlled JavaScript is executed.
- Required access: Ability to run code inside the vm2 VM (e.g., via APIs that accept dynamic scripts, plugins, or expressions).
- Trigger point: Execution of crafted sandboxed code that discovers and abuses the leaked host Object.
- Why exploitation is possible: The sandbox exposes a reference to the host Object, breaking isolation boundaries and allowing the guest code to reach host-level APIs or symbols, which can then be leveraged to escape and inject arbitrary code.
Why this happens
The underlying issue stems from incomplete isolation between the sandbox environment and the host Node.js runtime.
vm2's security model assumes that sandboxed code has no direct references to host-level objects; however, due to an implementation flaw, the host Object became reachable from within the sandbox.
Once this reference is obtained, JavaScript's reflective and metaprogramming capabilities (such as introspection via Symbols or property descriptors) can be used to traverse back into privileged host APIs.
This aligns with CWE-94: Improper Control of Generation of Code (Code Injection), because untrusted code gains a path to inject and execute arbitrary logic in a context that was supposed to be isolated.
Potential impact
- Execution of arbitrary JavaScript in the host Node.js process
- Complete sandbox escape, nullifying isolation guarantees
- Access to sensitive data and environment variables available to the host process
- Lateral movement within the application by invoking internal services or APIs
- Potential full compromise of the underlying server, depending on host privileges and integrations
General mitigation guidance
Mitigation strategies center on strengthening isolation boundaries and minimizing trust in sandboxing as a sole security control:
- Treat sandboxing libraries as defense-in-depth, not the only barrier between untrusted code and the host.
- Reduce the amount of untrusted code executed; prefer constrained, declarative configurations over dynamic code execution.
- Avoid exposing host objects, utilities, or global references into the sandbox wherever possible.
- Apply strict least-privilege policies to the host Node.js process (file system, network, and OS-level capabilities).
- Use process-level or container-level isolation (e.g., separate OS processes, containers, or jails) for high-risk code execution workloads.
- Regularly review sandbox configuration and ensure that any custom hooks or bridges do not leak host references.
How teams detect issues like this
Detection efforts can focus on both code-level patterns and runtime behavior:
- Static analysis and code review:
- Flag occurrences where user-supplied code or templates are executed within vm2.
- Review any bridging code that passes host objects into the vm2 context.
- Look for patterns exposing global objects, Symbols, or inspection utilities to sandboxed code.
- Policy and configuration checks:
- Enforce internal guidelines around safe sandbox use and restricted host interactions.
- Require security review for any new feature that evaluates user-controlled scripts, plugins, or expressions.
- Runtime monitoring:
- Monitor for unusual behavior from processes running vm2, such as unexpected file system or network access.
- Use logging around sandbox executions to track which inputs are executed and correlate with suspicious behavior.
- Automated tools can assist by scanning repositories for dynamic code execution patterns and known unsafe sandbox usage, but should be combined with manual review for context.

