开发者

Run Java programs from PHP in a sandbox

开发者 https://www.devze.com 2023-03-25 12:54 出处:网络
I have a little question: we have to run Java programs and parts of the code will be uploaded by the users.

I have a little question: we have to run Java programs and parts of the code will be uploaded by the users. So I want to know what's the best way to run them? I know 2开发者_运维技巧 possible ways,

  1. exec("javac Usercode.class") and then run the whole thing with exec("java Main"), but I tried it with exec() and it don't work. maybe because the http is not root? But I don't know exactly why.
  2. http://php-java-bridge.sourceforge.net/pjb/ ?

Any suggestions?

And another question is, how can I run these programs in a sandbox. we have a Debian server and so it's no problem to execute the command with a limited time, but is there a possible way to run the whole code in a sandbox?


Ideas for sandboxing:

  • Run in a chroot using e.g. Debian's schroot command. Protects against them accessing files outside of the chroot but not against them doing things like opening sockets etc.

  • Each user has their own Linux username against which they validate. Commands will then be run under the appropriate username (e.g. by using sudo or a set-uid executable).

  • Maintain a pool of virtual servers - expensive and complicated but gives best isolation.

0

精彩评论

暂无评论...
验证码 换一张
取 消