The vulnerability exists in the vm2 library due to an insecure implementation of the then and catch methods on the Promise object within the sandbox. These methods, located in lib/setup-sandbox.js, used Function.prototype.call to invoke the underlying promise handlers. This created a security flaw where code running inside the sandbox could override Function.prototype.call to intercept the execution flow. When an async function's promise resolved or rejected, the attacker's malicious call function would be triggered, giving it access to function references and objects from the host environment. The provided exploit leverages this by using the .catch handler to access the host's Error object, and from there, the host's Function constructor, which is then used to execute arbitrary commands on the host system, thus escaping the sandbox. The patch mitigates this by replacing the vulnerable .call() usage with Reflect.apply, which is not susceptible to the same kind of prototype-based attack.