A (node) module for running code with a controlled global context.
This module is intended to provide more deterministic controls to the native
vm library.
- Prevent access to
processinside VM - Support multiple input types for code
npm i @whi/isolated-executionimport { VM, Script } from '@whi/isolated-execution';
let vm = new VM({
console,
});
let code = new Script(() => {
console.log("Hello world");
});
vm.run( code );
code.run( context );When the run input is a function, input/output controls are supported.
let vm = new VM({});
let greeting = vm.run( ( first_name, last_name ) => {
return `Hello, ${first_name} ${last_name}`;
}, "Robin", "Williams" );
// Hello, Robin WilliamsSee docs/API.md
See CONTRIBUTING.md