So what I am trying to do is as take a javascript code as input from user and return him the result. Right now I am executing the code submitted by user just using eval (with some safety checks). But I understand this is highly unreliable. So what I want to achieve is run this in sandbox environment safely and return the result to user. E.g
Input:
var a =[1,2,3];
a.map(n => n*2);
Output:
[2,4,6]
I tried using vm in node but I don't really understand how to get the final result from it.