Lately am building an API with Node.js that receives untrusted code to run it using vm2.
The issue is I want to run async functions, so I need to use NodeVM
which does not support timeout for infinite loop, the solutions that I found all about using child process then kill it if it's not working.
But I am receiving the code as a string and I want to prevent having an infinite loop in it, so I thought of using regex to inject the while/for loop with a timeout condition or something so throw an exception whenever infinite loop happened.
Is that possible?