Besides infinite loops, I presume that you also worry
about memory allocations, and in general, allocation of resources.
You need
BSD::Resource to impose resource limits. (Depending
on your operating system, you can limit consumption of some resources.)