OhMyVm is a simple JavaScript virtual machine for node.js powered by Boa JavaScript engine. It is meant to be used for executing untrusted code in a sandboxed environment with little to no access to the host system.
npm install @ohmyvm/vm
const { OhMyVm } = require('@ohmyvm/vm');
const vm = new OhMyVm();
const code = Buffer.from(`
function main() {
return "Hello, World!";
}
main();
`);
const result = vm.eval(code);
// "Hello, World!"
console.log(result);
Creates a new instance of the virtual machine.
Evaluates the given code in the virtual machine and returns the result as a string. If the code throws an error, this method will throw an error as well.
The current maximum number of iterations allowed in a loop.
Sets the maximum number of iterations allowed in a loop. Setting this to a fixed number can help prevent infinite loops.
Disables loop iteration limit.
The current maximum depth of recursion allowed in a function.
Sets the maximum depth of recursion allowed in a function. Setting this to a fixed number can help prevent stack overflows.
The current maximum stack size allowed for the virtual machine.
Sets the maximum stack size allowed for the virtual machine. Setting this to a fixed number can help prevent stack overflows.
Enables or disables strict mode for the virtual machine.