In general - you can't. this is a classic CS problem - there is no way to algorithmatically determine (for every program) if a computer program is going to end.
If you really need more safe-guards than standard eval, look into alarm (which is still not 100%)