简体   繁体   中英

How to end any code currently being run by Node VM2

I am running some sandboxed code in Node using vm2 .

The code being run will be mostly asynchronous. It is untrusted code, and can not be relied upon to conform in any way- hence why I'm using vm2 to run it.

Does vm2 have a way of ending any code currently executing? The documentation is very limited. For example, if I were to have this code:

var code = 'setInterval(function(){ console.log("tick"); }, 1000);'
vm.run(code);

Is there any way I could run such the above, and halt it at some point in the future, without the controlling code having to know anything about the contents of code , and without code having to provide any specific features?

I cannot find a vm.stop() method or similar.

Unfortunately, there isn't a way to interrupt execution of the code running in the VM. The vm2 library is based on Node's VM module which doesn't provide any method to interrupt code running in the sandbox. At least not at the moment of writing this.

The only thing you can limit is the duration of any synchronous execution.

Disclaimer: I'm the author vm2 library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM