Summary
Enclave's JavaScript sandbox (enclave-vm) allowed untrusted code to escape the sandbox by accessing a host Error object whose prototype chain still pointed into the host Node.js realm.
By walking this prototype chain to the host Function constructor, an attacker could compile and run arbitrary JavaScript in the host context, breaking isolation and gaining access to environment variables, filesystem, and network APIs.
Affected context
This vulnerability affects deployments that run untrusted or semi-trusted JavaScript inside Enclave's enclave-vm sandbox, particularly where:
- Tool invocations or host integrations can throw errors that are surfaced to sandboxed code
- Error objects originating in the host are passed into the sandbox without being fully declassified or cloned into the sandbox realm
- The sandbox relies on JavaScript realm separation and constructor blocking to prevent access to powerful host primitives such as Function, eval, or process
In such configurations, a single exposed host Error instance can act as a capability to re-enter the host execution context.
Exploit preconditions
- Attack surface: JavaScript code executed inside enclave-vm that can:
- Invoke tools or APIs that may fail, or
- Receive propagated errors originating from the host environment
- Required access: Ability to submit or control code that runs inside the Enclave sandbox (e.g., user-supplied agents, plugins, extensions, or third-party workflows).
- Trigger point:
- Cause a tool invocation or host interaction to fail in a controlled way
- Receive the resulting host Error object inside the sandbox
- Traverse the Error object's prototype chain to discover the host realm Function constructor
- Why exploitation is possible:
- The Error object is not "rehosted" or fully wrapped; it retains its original prototype chain from the host realm.
- That prototype chain references native host constructors and objects that are supposed to be hidden from sandboxed code.
- The Function constructor obtained from the host realm can compile and execute arbitrary JavaScript with full host privileges, bypassing sandbox restrictions.
Why this happens
The core issue is a sandbox boundary violation caused by leaking a host realm object into the untrusted realm without removing its powerful prototype chain.
Conceptually, enclave-vm intends to create a hermetic JavaScript environment where dangerous globals (such as Function, eval, and process) are removed or replaced to prevent untrusted code from reaching host capabilities. However, when a host-side Error is passed into the sandbox after a tool failure, enclave-vm preserves the Error's original prototype chain. That prototype chain links back to host realm constructors and built-ins, including the host Function constructor.
This aligns with CWE-94: Improper Control of Generation of Code ('Code Injection') because the attacker gains the ability to generate and execute arbitrary code by reaching a powerful constructor that should have been inaccessible. It also reflects a failure in CWE-693: Protection Mechanism Failure, since the sandbox mechanism meant to isolate untrusted code is undermined by an inconsistent object wrapping policy. Instead of treating all cross-realm values as untrusted data that must be deeply cloned or safely proxied, the implementation allows a "capability-bearing" object to cross the boundary unmodified, opening a direct path back to host execution.
Potential impact
- Execution of arbitrary JavaScript in the host Node.js runtime from within the sandbox.
- Access to sensitive runtime data, such as:
process.env(credentials, API keys, tokens, configuration secrets)- Process arguments and runtime configuration.
- Arbitrary file system access (read/write/delete) through Node.js fs APIs.
- Outbound network access using host networking libraries and sockets.
- Lateral movement within the hosting environment, including:
- Pivoting to other internal services reachable from the host.
- Exfiltration of data or secrets from adjacent components.
- Full compromise of the application process in which enclave-vm runs, including potential use as a launchpad for broader infrastructure attacks.
General mitigation guidance
Effective mitigation focuses on hardening sandbox boundaries and ensuring that no host realm capabilities leak into the untrusted environment:
- Strict object boundary enforcement:
- Treat any value crossing from host to sandbox as untrusted data.
- Deep-clone or serialize/deserialize objects so that sandboxed code only sees plain data structures with prototypes rooted in the sandbox realm.
- Avoid passing native host objects (Error, Function, Promise, etc.) directly into the sandbox.
- Prototype and constructor isolation:
- Ensure that all sandbox-visible objects have prototype chains confined to the sandbox realm.
- Strip or neutralize prototype links that could reveal host constructors or built-ins.
- Block or tightly control access to powerful constructors (Function, AsyncFunction) and evaluation primitives within the sandbox.
- Error and exception declassification:
- Transform host errors into inert data representations (e.g., structured error info) before exposing them to sandboxed code.
- Avoid passing original Error instances, stack traces, or host-specific error types across the boundary.
- Principle of least privilege for host integrations:
- Design tools and host APIs exposed to the sandbox so that, even if misused, they cannot escalate privileges or leak raw host objects.
- Prefer narrow, well-typed interfaces over generic "escape hatches" that return arbitrary objects.
- Defense-in-depth around the sandbox:
- Run sandbox processes under minimised OS and container privileges.
- Restrict filesystem, environment, and network permissions at the platform level so that a sandbox escape has reduced blast radius.
How teams detect issues like this
Detection typically combines code-level analysis with behavioral monitoring:
- Static analysis and code scanning:
- Search for direct passing of host realm objects (especially Error instances) into sandbox execution APIs.
- Flag code paths where cross-realm values are not cloned, serialized, or wrapped before being returned to untrusted code.
- Look for references to host constructors or globals (Function, eval, process) becoming accessible from sandboxed code paths.
- Security-focused code review:
- During review of sandbox or plugin infrastructure, verify that:
- All values crossing between host and sandbox pass through a well-defined marshalling layer.
- Error handling paths do not leak native Error objects or stack-trace frames directly.
- Treat any "realm crossing" boundary as a high-risk area requiring explicit threat modeling.
- Runtime monitoring and policy enforcement:
- Instrument host code to detect unexpected usage of powerful primitives originating from sandboxed call stacks (e.g., Function constructor calls or dynamic code generation traced back to sandbox entrypoints).
- Apply application-level policies to disallow or alert on dynamic code evaluation originating from untrusted workflows.
- Use of automated review tools:
- Employ linters and SAST tools with rules tailored to sandbox frameworks, focusing on:
- Cross-realm object flows
- Dynamic evaluation APIs
- Direct access to process, fs, and net modules from code intended to be confined.

