public
Created

  • Download Gist
README
1 2 3 4 5 6 7
securely running untrusted code in Node.js
 
Usage:
$ node sandbox.js
 
based on LintServer by Jakob Kruse:
https://github.com/jkruse/LintServer
sandbox.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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);
untrusted.js
JavaScript
1 2 3 4
var fs = require("fs");
 
var text = fs.readFileSync("./dispatch.js", "utf8");
console.log(text);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.