i am using https://github.com/gf3/sandbox#readme but i am not getting that how can i pass some data from my code to javascript code through this sandbox. for example
var s = new sandBox();
s.run("(function(name) { return 'Hi there, ' + name + '!'; })('Fabio')", function(output) {
console.log("Example 2: " + output.result + "\n")
})
now i want to pass some data to this function how can i do that?
It does not have any clean way to pass arguments. However, since you are passing code as a string anyway, you can simply add the arguments directly to the string:
var arg = 'Hello';
var code = "(function(name) { return 'Hi there, ' + name + '!'; })("+ JSON.stringify(arg) +")"
s.run(code, ...);
I'm using JSON.stringify
to ensure that the string is a valid JS expression.