def make_secure(): UNSAFE_BUILTINS = ['open', 'file', 'execfile', 'compile', 'reload', '__import__', 'eval', 'input'] ## block objet? for func in UNSAFE_BUILTINS: del __builtins__.__dict__[func] from re import findall make_secure() print 'Go Ahead, Expoit me >;D' while True: try: inp = findall('\S+', raw_input()) a = None exec 'a=' + inp print 'Return Value:', a except Exception as e: print 'Exception:', eHowever, just deleting functions from the __builtins__ dictionary does not completely eliminate references to them. By traversing class and subclass trees, we eventually get a reference to 'file' because it is a subclass of the 'object' type. Below is a way of taking a list (with a single number in it) and getting a reference to the 'file' function (it is the 40th item in the list when I ran it).
(1337).__class__.__bases__.__subclasses__() # This references the function 'file'We can therefore open an arbitrary file and read the key now.