I'm looking for a solution to evaluate a piece of python code and should make a decision whether or not it is safe to run using eval(...). This means it should check if there are imports, system calls, any other possible exploits or dangerous calls in order to make sure the code (which will be input by an user) is safe to run.

Are there any such libraries? (preferably open-source) Any advantages or disadvantages to any specific library?

It was also brought up that even with code that will be passed as safe, a malicious (or curious) user can still pass something that will consume all your memory and crash, or just take an endless amount of time to complete such as: