How to run java code in a restricted sandbox (without network, filesystem access)

故事扮演 提交于 2019-12-30 03:11:05

问题


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).


回答1:


You can control the environment using policy files http://docs.oracle.com/javase/1.4.2/docs/guide/security/PolicyFiles.html#Examples

you could run then run your jar

java -Djava.security.manager -Djava.security.policy=/path/your_policy_file.policy -jar




回答2:


This page describes the process in detail:

http://www.jayway.com/2014/06/13/sandboxing-plugins-in-java/



来源:https://stackoverflow.com/questions/9192493/how-to-run-java-code-in-a-restricted-sandbox-without-network-filesystem-access

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!