Summary
SandboxJS prior to version 0.8.29 contains a sandbox escape issue where return values of functions are not safely wrapped, allowing access to the host environment's Function constructor.
By chaining built‑in methods like Object.values, Object.entries, and Array.prototype.at, an attacker can obtain the host Function constructor and execute arbitrary code outside of the intended JavaScript sandbox boundaries.
Affected context
This vulnerability affects applications that embed untrusted or partially trusted JavaScript using SandboxJS versions prior to 0.8.29.
It becomes relevant when:
- The sandbox is relied upon as a strong isolation boundary between untrusted code and the host environment.
- Untrusted code can call functions that internally access host objects, with their return values exposed directly to sandboxed code.
- The application assumes that built-in language features (like
Object.*andArray.*) cannot be used to escape the sandbox.
In such setups, the sandbox may provide only the illusion of isolation while still leaking powerful references into the guest code.
Exploit preconditions
- Attack surface: JavaScript execution environment where untrusted or semi-trusted scripts are run under SandboxJS.
- Required access: Ability to execute or influence code that runs inside the SandboxJS instance (e.g., user-supplied scripts, plugins, templates, or extensibility hooks).
- Trigger point: Invocation of functions that return objects containing references to host-level constructors or methods, which are then processed via
Object.values/Object.entriesandArray.prototype.at. - Why exploitation is possible: SandboxJS does not fully wrap or neutralize function return values, allowing internal references (including the host's
Functionconstructor) to leak into the sandboxed context. Once obtained,Functioncan be used to construct and run arbitrary code in the host context, bypassing sandbox restrictions.
Why this happens
The core issue is incomplete mediation of object graphs crossing the sandbox boundary.
SandboxJS attempts to restrict what sandboxed code can access, but it does not consistently wrap or proxy the return values of functions that originate from the host environment.
As a result, sandboxed code can use built-in enumeration helpers (Object.values, Object.entries) and positional access (Array.prototype.at) to traverse returned objects and eventually reach the native Function constructor.
This pattern maps to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component, in the sense that untrusted code can inject or construct executable code in a downstream execution engine (the host JavaScript environment) because critical elements (like Function and its arguments) are not adequately controlled at the trust boundary.
Potential impact
- Execution of arbitrary JavaScript code in the host environment, bypassing sandbox restrictions.
- Access to sensitive in-memory data, including secrets, tokens, or user information available to the host process.
- Modification of application state, including tampering with security checks, business logic, or user data.
- Lateral movement within the hosting environment, such as invoking host APIs, performing network requests, or interacting with the filesystem (where available).
- Complete compromise of the security guarantees expected from using SandboxJS as an isolation mechanism.
General mitigation guidance
Effective mitigation centers on reinforcing the trust boundary between sandboxed and host code, and ensuring no powerful references leak into untrusted contexts.
Pattern-based guidance includes:
- Comprehensive wrapping/proxying of return values: Ensure that any object, function, or constructor exposed to sandboxed code is passed through a strict proxy or wrapping layer that filters or replaces dangerous properties such as
constructor,__proto__, andFunction. - Deny access to powerful constructors: Prevent sandboxed code from obtaining references to
Function,eval, or other dynamic code construction mechanisms. This may require structural filtering of object graphs before they are visible to the sandbox. - Minimize host object exposure: Design the sandbox API so that host objects are represented with minimal, purpose-built facades rather than exposing rich native objects or generic containers.
- Implement allowlists over denylists: Define explicit, minimal sets of safe properties and methods that can be accessed from sandboxed code, rather than trying to blacklist known-dangerous ones.
- Harden built-in method handling: Audit how language built-ins like
Object.values,Object.entries, and array access helpers interact with wrapped objects, and ensure wrappers preserve security invariants even under introspection and enumeration. - Defense in depth at the application layer: Treat sandboxed execution as one layer of security; combine it with process isolation, least-privilege runtime permissions, and strict input validation on data returning from sandboxed code.
How teams detect issues like this
Detection focuses on identifying insecure sandbox boundaries and leaked powerful references:
- Static analysis and linting:
- Search for uses of SandboxJS or similar libraries where untrusted code is executed, and verify that wrapping and proxying are consistently applied to function return values.
- Flag instances where host functions or constructors are passed directly into the sandbox without mediation.
- Code review heuristics:
- Review sandbox adapter layers for exposure of rich host objects, especially those with access to
constructorproperties or prototypes. - Inspect any bridging code that returns complex objects to the sandbox and ensure that it applies a strict transformation or proxy.
- Look for assumptions in comments or docs claiming "full isolation" without evidence of systematic wrapping.
- Runtime monitoring and policies:
- Instrument sandbox environments to log attempts to access
Function,eval, or other dynamic evaluators, and treat such access as an indicator of possible sandbox escape attempts. - Use security-focused automated tests or fuzzing that exercise built-in object enumeration and introspection patterns (
Object.keys,Object.values,Object.entries, spread syntax) to discover unexpected escape paths. - Automated tooling:
- Integrate security scanners or SAST tools that understand common sandbox patterns and can flag exposed constructors and unwrapped object graphs as potential vulnerabilities.

