title: How do you create a secure JEXL (scripting) sandbox?
body: <p>I'm creating a sandbox for JEXL scripts to execute in so that a malicious user can't access data outside the variables we give them access to and also can't perform a DOS attack on the server. I'd like to document this for anybody else also doing this and also get other people's input into the approach.</p>
  
  <p>The following is a list of the things I'm aware of that needs to be addressed:</p>
  
  <ol>
  <li>Only allow instantiating classes using 'new' that are on a whitelist.</li>
  <li>Do not allow accessing the getClass method on any class because then forName can be called and any class can be accessed.</li>
  <li>Restrict access to resources such as files.</li>
  <li>Allow an expression only a certain amount of time to execute so that we can limit the amount of resources it consumes.</li>
  </ol>
  
  <p>This does not apply to JEXL but may apply to the scripting language you are using:</p>
  
  <ol>
  <li>Do not allow an object to have a custom finalize method because the finalize method is called from the finalizer thread and will execute with the original AccessControlContext instead of the one being used to create the object and execute the code in it.</li>
  </ol>