Skip to content

Instantly share code, notes, and snippets.

@onteria
Created June 3, 2011 19:33
Show Gist options
  • Save onteria/1007004 to your computer and use it in GitHub Desktop.
Save onteria/1007004 to your computer and use it in GitHub Desktop.
Running sandboxed code using vm
server.on("response", function(response) {
fs.readFile('untrusted.js', function(err,data){
var loaded_module = vm.createScript(data, 'untrusted.js');
loaded_module.runInNewContext({response: response});
})
});
// untrusted.js
(function () {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment