Embedding a restricted python interpreter

Doug Holton a at b.c
Thu Jan 6 21:34:31 EST 2005


Rolf Magnus wrote:
> Hi,
> 
> I would like to embed a python interpreter within a program, but since that
> program would be able to automatically download scripts from the internet,
> I'd like to run those in a restricted environment, which basically means
> that I want to allow only a specific set of modules to be used by the
> scripts, so that it wouldn't be possible for them to remove files from the
> hard drive, kill processes or do other nasty stuff.
> Is there any way to do that with the standard python interpreter?

Hi, there is a page on this topic here:
http://www.python.org/moin/SandboxedPython

The short answer is that it is not possible to do this with the CPython, 
but you can run sandboxed code on other virtual machines, such as Java's 
JVM with Jython, or .NET/Mono's CLR with Boo or IronPython.

In the future it may also be possible to do this with PyPy or Parrot.



More information about the Python-list mailing list