▲ | high_byte 7 months ago | |
I didn't use RestrictPython. I did manage to patch the __subclasses__() escape with a hack. if only I can patch the exceptions traceback too I think it will be good enough :) edit: here are my silly little patches: https://github.com/hananbeer/cpython-toy-sandbox/commit/fa3f... this is of course assuming exec(globals={..}) without certain builtins and is, again, not expected to use system apis like files or sockets or anything. | ||
▲ | eesmith 7 months ago | parent [-] | |
As a reminder, in case you didn't consider it, some code in your exec string might be run after the exec has finished, due to garbage collection.
The output for this on my system is
which means you'll need to ensure those dictionaries are cleared and garbage collected before you can clear your toybox state, something like:
The "del" is not good enough due to the cyclical reference as the iterator function's globals contain the active iterator.If you allow any mutable object into the globals or locals dictionary, such that the exec'ed code can attach something to it, then you can't even use gc.collect() to ensure the exec'ed code can no longer be executed. |