Menu

Home

Arka Majumdar

The Java Sandbox Library is a beta project. If you find a bug or have a question, please email me at dudeprgm@gmail.com.

The main class of the library is the Sandbox class. You'll find all the information you need in the javadoc in the the "Files tab", but here's an example to get you started:

Sandbox.doUntrusted(new UntrustedAction<Void>(new PermissionsSecurityManager()) {
    protected Void run() {
        // [untrusted code goes here]
        // this code will have absolutely no permissions
        // to do any potentially unsafe actions
        return null;
    }
})

This will grant the untrusted code no permissions whatsoever. If you want to fine tune the Permissions granted to the code, you can replace the new PermissionsSecurityManager() with new PermissionsSecurityManager(new PermissionSubclass(), new PermissionSubclass). Go the javadoc of the Permissions Class in Java and look at all the subclasses to see what all permissions you can grant.

The other security managers you can use instead of PermissionsSecurityManager are the CheckingSecurityManager and the SwitchableSecurityManager.

Use the CheckingSecurityManager to restrict a specific class, or you can use the SwitchableSecurityManager that you can turn off and on within the code (not recommended in general, especially not recommended for multithreaded applications).

Most of the methods in the SecurityManager classes should be self-explanatory.

Hope this wiki helped!

(By the way, if you are interested, I am looking for people to maintain the library. If this sounds like something you want to do, please contact me at dudeprgm@gmail.com).

Project Members: