/

CVE-2026-24118

Severity:

CRITICAL RISK

(9.8)

Code Injection / Sandbox Escape in vm2 Node.js Sandbox

CVE-2026-24118

Modified

Vulnerability type

Category:

Code Injection / Sandbox Escape

CWE:

CWE-94, CWE-693, CWE-749

Impact:

Remote Code Execution via Sandbox Escape

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

vm2, a popular sandboxing library for Node.js, contained a sandbox breakout flaw that allowed untrusted code to escape the virtualized environment.

In vulnerable versions, an attacker-controlled script running inside vm2 could execute arbitrary commands on the host system, effectively achieving remote code execution when vm2 is used to run untrusted input.

Affected context

This vulnerability affects applications that embed vm2 as a security boundary to execute untrusted or partially trusted JavaScript.

It becomes relevant when:

  • vm2 is treated as the primary containment mechanism for attacker-supplied or tenant-supplied code, and
  • the host process has meaningful OS-level privileges (access to filesystem, network, environment variables, or secrets).

In such deployments, any escape from the vm2 sandbox undermines assumptions about isolation between user code and the host environment.

Exploit preconditions

  • Attack surface: The vm2 sandbox interface exposed by the host application (e.g., APIs that accept user code or user-defined scripts).
  • Required access: Ability to supply or influence JavaScript that is executed inside a vm2 VM instance (e.g., multi-tenant platforms, online code runners, plugin systems, scriptable bots).
  • Trigger point: Execution of attacker-controlled code in a vm2 sandbox under vulnerable versions prior to 3.11.0.
  • Why exploitation is possible: The sandbox implementation contained a flaw that allowed crafted code to traverse or bypass isolation boundaries and obtain a reference to privileged objects or APIs, enabling arbitrary command execution on the host.

Why this happens

The underlying issue fits CWE-94: Improper Control of Generation of Code ('Code Injection'), combined with a failure of the sandbox enforcement mechanisms (related to CWE-693: Protection Mechanism Failure).

vm2 attempts to create a restricted execution environment by wrapping Node.js primitives and limiting access to host objects. A subtle design or implementation weakness allowed sandboxed code to influence or access interpreter capabilities and host APIs that were assumed to be hidden.

In abstract terms, the bug arises when user-controlled code is executed with the expectation of strict isolation, but the sandbox leaves a pathway to powerful native capabilities (such as child process execution or unrestricted require access). This breaks the trust boundary between "untrusted" and "trusted" code, effectively converting what should be pure data or controlled scripts into a vehicle for host-level code injection.

Potential impact

  • Arbitrary command execution on the host operating system running the Node.js process
  • Complete compromise of the application process, including access to memory, environment variables, secrets, and configuration
  • Unauthorized reading, modification, or deletion of files accessible to the Node.js runtime
  • Abuse of network access from the host to pivot to internal services or exfiltrate data
  • Escalation from a single-tenant sandbox to full multi-tenant compromise in platforms that rely on vm2 for isolation between users

General mitigation guidance

Effective mitigation focuses on both hardening the sandbox boundary and assuming that sandboxes can fail:

  • Treat sandboxing libraries as defense-in-depth, not the sole security barrier, especially for attacker-controlled code.
  • Minimize the privileges of the Node.js process that hosts vm2:
  • Run with least-privilege OS accounts and restricted filesystem access.
  • Limit available environment variables and credentials.
  • Constrain outbound network access where feasible.
  • Restrict the capabilities available inside the sandbox:
  • Avoid exposing powerful APIs (e.g., unrestricted require, access to child processes, or direct FS access) to user code.
  • Enforce strict whitelisting of modules and globals visible inside the VM.
  • Isolate untrusted code in separate OS-level or container-level sandboxes (e.g., lightweight containers, separate processes with IPC, or dedicated worker nodes) so that a JavaScript sandbox escape does not equate to full host compromise.
  • Incorporate regular security review of sandbox usage patterns and ensure that security assumptions about isolation are explicitly documented and periodically revisited.

How teams detect issues like this

Detection typically combines code-centric and architecture-level checks:

  • Static analysis and code review:
  • Flag use of vm2 (or similar sandboxes) as a security boundary, requiring explicit review.
  • Check for patterns where untrusted input is executed via vm2 without additional isolation (e.g., no process or container separation).
  • Identify exposure of sensitive host APIs into the sandbox context (e.g., passing in host objects, unrestricted require).
  • Runtime monitoring:
  • Monitor sandboxed execution for anomalous behavior, such as unexpected process creation, filesystem access, or outbound connections originating from worker processes intended only for limited computation.
  • Use logging to record when and how user code is executed, enabling investigation of suspicious execution patterns.
  • Policy enforcement:
  • Security policies in CI/CD to flag or block deployments that rely solely on in-process sandboxes for hosting untrusted code.
  • Optional use of automated SAST/DAST tools configured to recognize sandbox escape risks and protection mechanism failures.

Sources

SourceLink
github.comgithub.com/patriksimek/vm2/commit/2b5f3e3a060d9088f5e1cdd585d683d491f990a3
github.comgithub.com/patriksimek/vm2/commit/f9b700b1c7d9ef2df416666cb24e0b659140cc74
github.comgithub.com/patriksimek/vm2/releases/tag/v3.11.0
github.comgithub.com/patriksimek/vm2/security/advisories/GHSA-grj5-jjm8-h35p
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-24118
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2466502
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-24118.json

Frequently asked

questions

It can be, depending on how vm2 is used. If a service exposes an API or interface that lets remote users submit JavaScript to run inside vm2, a remote attacker may leverage this flaw to execute commands on the host.

The attacker needs the ability to run or influence code that is executed inside a vm2 VM instance. This might be through a public API, a plugin system, a scripting feature exposed to end users, or any mechanism that executes user-supplied code using vm2.

Architect systems so that vm2 (or any in-process sandbox) is not the only security barrier. Run untrusted code in heavily constrained environments—such as separate processes, containers, or isolated workers—configured with least privilege, strict filesystem and network restrictions, and minimal access to secrets.

Avoid treating language-level sandboxes as absolute isolation boundaries, perform regular security review of untrusted-code execution paths, and combine multiple layers of isolation (process, container, network, and access control). Establish clear policies that any feature executing user-supplied code must undergo threat modeling and security testing focused on sandbox escape and privilege escalation scenarios.

Find out what's already
exploitable in your codebase.