sandbox/sandbox.js
function(code, url, done) {
  var vm = require('vm')
  var sandbox = {}
  var expose = [
    'application',
    'setTimeout',
    'setInterval',
    'clearTimeout',
    'clearInterval'
  ]

  for (var i = 0; i < expose.length; i++) {
    sandbox[expose[i]] = global[expose[i]]
  }

  code = '"use strict";\n' + code
  try {
    vm.runInNewContext(code, vm.createContext(sandbox), url)
    done()
  } catch (e) {
    done(e)
  }
}
function(code, url, done) {
  var vm = require('vm')
  var sandbox = {}
  var expose = [
    'application',
    'setTimeout',
    'setInterval',
    'clearTimeout',
    'clearInterval'
  ]

  for (var i = 0; i < expose.length; i++) {
    sandbox[expose[i]] = global[expose[i]]
  }

  code = '"use strict";\n' + code
  try {
    vm.runInNewContext(code, vm.createContext(sandbox), url)
    done()
  } catch (e) {
    done(e)
  }
}
function ( code , url , done ) { var vm = require ( 'vm' ) var sandbox = { } var expose = [ 'application' , 'setTimeout' , 'setInterval' , 'clearTimeout' , 'clearInterval' ] for ( var i = 0 ; i < expose . length ; i ++ ) { sandbox [ expose [ i ] ] = global [ expose [ i ] ] } code = '"use strict";\n' + code try { vm . runInNewContext ( code , vm . createContext ( sandbox ) , url ) done ( ) } catch ( e ) { done ( e ) } }
Executes the given code in a jailed environment, runs the
corresponding callback when done

@param {String} code to execute
@param {String} url of the script (for displaying the stack)
Executes the given code in a jailed environment runs the corresponding callback when done