Say some programmer gives me an executable jar (from Java code) along with the entry point to use. I want to run this jar (programmatically) from Java code in a restricted sandbox environment with no network or filesystem access or database access and a fixed amount of CPU and memory. I.e., the Java code should not cause any side effects on other programs running on the my jvm.
Ideally I would like to allow certain access based on situation (say for example, only files in a certain directory with quota).
You can control the environment using policy files http://docs.oracle.com/javase/1.4.2/docs/guide/security/PolicyFiles.html#Examples (archived version @archive.org)
you could run then run your jar
java -Djava.security.manager -Djava.security.policy=/path/your_policy_file.policy -jar
This page describes the process in detail:
http://www.jayway.com/2014/06/13/sandboxing-plugins-in-java/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With