Create a gist now

Instantly share code, notes, and snippets.

Created Feb 3, 2011

securely running untrusted code in Node.js
$ node sandbox.js
based on LintServer by Jakob Kruse:
var fs = require("fs");
var vm;
try {
vm = require("vm");
} catch(exc) { // Node.js v0.2
vm = process.binding("evals").Script;
var filename = "untrusted.js";
var source = fs.readFileSync("./" + filename, "utf8");
var sandbox = {};
vm.runInNewContext(source, sandbox, filename);
var fs = require("fs");
var text = fs.readFileSync("./dispatch.js", "utf8");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment