http://www.perlmonks.org?node_id=55350

Fastolfe has asked for the wisdom of the Perl Monks concerning the following question:

I have in the past and am considering in the future using the Safe module to provide semi-public access to a local Perl interpreter. I'm familiar with all of the options and opcode groups, and can configure it to be what appears to be completely safe as far as executing untrusted code goes. My questions are these:
  1. The Safe documentation makes it plain and clear that using the module is no guarantee of security/safety in executing untrusted code. Barring any undiscovered bugs/exploits, however, is it for all practical purposes reasonably safe to use it in this fashion? Is there some fundamental flaw in its implementation or are there any known ways of circumventing its protection? I realize there's always the possibility of some hole allowing unauthorized access to certain Perl opcodes, but I'm trying to identify the level of risk involved here.
  2. Is there an easy/common way of addressing the DoS aspect of running untrusted code? With Safe, I can prohibit them from executing stuff I don't want them to execute, but I can't keep them from writing a tight while (1) {} loop and tying up the CPU, or making it so the code never returns. My first thought is to use setpriority to reduce adverse affects, and alarm to catch any code running an inordinate amount of time, but is this safe? What if the evil code modifies $SIG{ALRM}?
I realize this is a risky thing to do, and additional security precautions I'm considering involve chroot and others. Can anyone think of any other caveats?