| A Python interpreter with costed opcodes would be smart. But then still there is no oracle to predict whether user-supplied [RestrictedPython] code never halts; so, without resource quotas from VMs or Containers, there is unmitigated risk of resource exhaustion from user-supplied and developer-signed code. IIRC there are one-liners that DOS Python and probably RestrictedPython too. JupyterHub Spawners and Authenticators were created to spin up [k8s] containers on demand - with resource quotas - for registered users with e.g. JupyterHub and unregistered users with BinderHub. Someone already has a presentation on how it's impossible to fully sandbox Python without OS process isolation? You can instead have them run their code on their machine with Python in WASM in a browser tab; but should you trust the results if you do not test for convergence by comparing your local output with other outputs? Consensus with a party of one or an odd number of samples. So, reproducibility as scientific crisis: "it worked on my machine" or "it works on the gitops CI build servers" and "it works in any browser" and the output is the same when the user runs their own code locally as when it is run on the server [with RestrictedPython]. I heard it was actually impossible to sandbox Python (and most or all other languages) with itself? /? python sandbox RestrictedPython
https://google.com/search?q=python+sandbox+RestrictedPython |
This is actually something I was interested in a while ago, but in Scheme. For example GNU Guile has such a facility built in [0], though with a caveat that if you're not careful what you expose you could still make yourself vulnerable to DoS attack (the memory exhaustion kind). But if you don't expose any facility that allows the untrusted user to make large allocations at a time (in a single call) you should be fine (fingers crossed). I don't see a reason why the same mechanics couldn't be implemented in Python.
[0] https://www.gnu.org/software/guile/manual/html_node/Sandboxe...
Edit: in some sense this restricted python stuff also reminds me of Safe Haskell (extension) [1], which came out a bit ahead of it's time and by this point almost forgotten about. Might become relevant again in the future.
[1] https://begriffs.com/posts/2015-05-24-safe-haskell.html - better overview than the wiki page