title: Sandbox JVM to secure server from untrusted sources
body: <p>How can protecting my server from malicious activity when accepting and executing uploaded, untrusted code?</p>
  
  <p>The users should be able to implement my interface and given data, perform some calculations and return data. No I/O operations are required and certainly no thread/process manipulation or other tomfoolery.</p>
  
  <p>Using the java.policy file it is possible to deny everything (by granting nothing).</p>
  
  <pre><code>$ cat test.policy 
  grant {
  };
  </code></pre>
  
  <p>Using this policy file, operations not granted will cause a security exception.</p>
  
  <pre><code>$ cat Print.java
  public class Print {
      public static void main(String a[]) throws Exception {
          System.out.println(System.getProperty("os.name"));
      }
  }
  
  $ javac Print.java
  $ java -Djava.security.manager -Djava.security.policy==test.policy Print
  Exception in thread "main" java.security.AccessControlException: 
    access denied (java.util.PropertyPermission os.name read)
      at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
      at java.security.AccessController.checkPermission(AccessController.java:546)
      at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
      at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1285)
      at java.lang.System.getProperty(System.java:650)
      at Print.main(Print.java:3)
  </code></pre>
  
  <p>Is this foolproof? Do I need to do more to secure my server environment from untrusted sources?</p>