The vulnerability lies in the way vm2 handled Promise instantiation within the sandboxed environment. The security advisory GHSA-hw58-p9xv-2mjh and the corresponding patch make it clear that the localPromise class in lib/setup-sandbox.js was the source of the issue. Prior to the fix, localPromise was an empty extension of the host's Promise class, meaning it used the host's Promise constructor directly. This constructor did not have any mechanism to trap exceptions occurring within the executor function when called from the sandbox. As a result, a synchronous exception inside the executor would lead to an unhandled promise rejection on the host, which, by default in recent Node.js versions, terminates the process.
The patch rectifies this by implementing a custom constructor for localPromise. This new constructor wraps the sandboxed executor function in a try...catch block. If an exception is caught, it is passed to the handleException function to be safely sanitized before the promise is rejected within the sandbox's context. This prevents the exception from ever becoming an unhandled rejection on the host. The vulnerable function is therefore the Promise constructor available in the sandbox, which is localPromise.constructor.