feat: improve execute js/py code and collect results (#117)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
const vm = require('vm');
|
||||
|
||||
/**
|
||||
* Execute the javascript code in node.js.
|
||||
* @typedef {Object} Args
|
||||
@@ -5,5 +7,7 @@
|
||||
* @param {Args} args
|
||||
*/
|
||||
exports.run = function run({ code }) {
|
||||
return eval(code);
|
||||
const context = vm.createContext({});
|
||||
const script = new vm.Script(code);
|
||||
return script.runInContext(context);
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@ def run(code: str):
|
||||
Args:
|
||||
code: Python code to execute, such as `print("hello world")`
|
||||
"""
|
||||
return exec(code)
|
||||
return eval(code)
|
||||
Reference in New Issue
Block a user