Summary
SandboxJS fails to properly restrict the __lookupGetter__ API, allowing access to object prototypes from within the sandboxed environment.
If an attacker can run JavaScript code inside a SandboxJS instance, they may be able to escape the sandbox and achieve remote code execution in the host context.
Affected context
This vulnerability affects applications that embed untrusted or semi-trusted JavaScript inside SandboxJS for isolation.
It is relevant when:
- SandboxJS is used as the primary defense to contain untrusted scripts
- The environment exposes
__lookupGetter__or related prototype-manipulating APIs to sandboxed code - Host objects or powerful capabilities (e.g., file, network, process, or module access) are reachable via prototype chains
In these setups, a crafted script can leverage prototype access to break containment guarantees.
Exploit preconditions
- Attack surface: JavaScript execution environment where SandboxJS is used to run external or untrusted code
- Required access: Ability to supply or influence code executed inside a SandboxJS sandbox (e.g., plugin systems, user scripts, configuration-based code)
- Trigger point: Execution of attacker-controlled JavaScript that calls
__lookupGetter__(or equivalent) to traverse prototype chains - Why exploitation is possible: The sandbox does not sufficiently restrict access to prototype accessors, enabling retrieval of powerful host objects and eventual code execution outside the intended isolation boundary
Why this happens
The underlying issue is an incomplete isolation model around the JavaScript object system.
SandboxJS attempts to restrict what sandboxed code can reach, but leaves __lookupGetter__ available, which allows inspection and retrieval of getters associated with object properties.
Through this mechanism, an attacker can reach prototypes and potentially discover or construct references to privileged host objects and functions.
This behavior maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), because untrusted code is effectively able to generate or invoke code in the host context by bypassing intended sandbox restrictions.
Potential impact
- Sandbox escape from the JavaScript sandbox into the host execution environment
- Remote code execution with the privileges of the embedding application or service
- Access to sensitive in-memory data, configuration, or secrets available to the host process
- Abuse of filesystem, network, or process APIs exposed in the host environment
- Lateral movement within a system or infrastructure where the host application has elevated access
General mitigation guidance
Effective mitigation focuses on tightening the sandbox boundary and reducing trust in hosted scripts:
- Restrict or remove access to prototype manipulation APIs (
__lookupGetter__,__lookupSetter__, and related reflective capabilities) from sandboxed code - Isolate untrusted code in separate, least-privileged processes or runtimes rather than relying solely on in-VM sandboxes
- Minimize the capabilities and host-object surface area exposed to sandboxed code, following a strict allowlist model
- Apply a defense-in-depth approach: even if the sandbox fails, OS-level permissions, containerization, and network restrictions should limit the damage
- Treat the sandbox as one layer of protection rather than the only security boundary around untrusted code execution
How teams detect issues like this
Detection typically involves reviewing both sandbox configuration and code paths that expose host functionality:
- Static analysis or code review focused on:
- Calls to sandbox APIs that execute user-controlled or external JavaScript
- Instances where host objects, modules, or system APIs are passed into or exposed within the sandbox
- Continued availability of
__lookupGetter__,__lookupSetter__, or similar reflective APIs within sandboxed contexts - Security-focused tests that:
- Execute crafted scripts inside the sandbox to verify that prototype access and escape attempts are blocked
- Validate that host resources (filesystem, network, environment variables, process control) are not reachable from sandboxed code
- Policy enforcement in CI/CD pipelines to require manual review or automated checks when sandbox configuration or allowed host APIs change

