from Hacker News

Preventing Python "Sandbox" Escape?

by high_byte on 11/26/24, 10:39 AM with 13 comments

I'm using python's exec(code, globals, locals)

I disable __builtins__ so no imports, exec, eval, open, etc. inside that context

but it seems you can still always do object.__subclasses__() and find every system method (eg. open())

it can't be overwritten but looking at the interpreter code is seems like it's possible to hack a workaround for this specific case.

are there other known ways to escape exec()?