How to use the vm2/package.json.version function in vm2

To help you get started, we’ve selected a few vm2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CapacitorSet / box-js / analyze.js View on Github external
// See https://github.com/nodejs/node/issues/8071#issuecomment-240259088
// It will prevent console.log from calling the "inspect" property,
// which can be kinda messy with Proxies
require("util").inspect.defaultOptions.customInspect = false;

if (argv["dangerous-vm"]) {
	lib.verbose("Analyzing with native vm module (dangerous!)");
	const vm = require("vm");
	vm.runInNewContext(code, sandbox, {
		displayErrors: true,
		// lineOffset: -fs.readFileSync(path.join(__dirname, "patch.js"), "utf8").split("\n").length,
		filename: "sample.js",
	});
} else {
	lib.debug("Analyzing with vm2 v" + require("vm2/package.json").version);
	const vm = new VM({
		timeout: (argv.timeout || 10) * 1000,
		sandbox,
	});

	vm.run(code);
}

function ActiveXObject(name) {
	lib.verbose(`New ActiveXObject: ${name}`);
	name = name.toLowerCase();
	if (name.match("xmlhttp") || name.match("winhttprequest"))
		return require("./emulator/XMLHTTP");
	if (name.match("dom")) {
		return {
			createElement: require("./emulator/DOM"),

vm2

vm2 is a sandbox that can run untrusted code with whitelisted Node's built-in modules. Securely!

MIT
Latest version published 2 years ago

Package Health Score

43 / 100
Full package analysis