Is there a "safe" subset of Python for use as an embedded scripting language?

Here are a couple of links to give you an idea on what you're up against:

  • How can I run an untrusted Python script safely (i.e. Sandbox)
  • Capabilities for Python? by Guido himself

There is also a dead google code project at http://code.google.com/p/sandbox-python/


The PyMite VM fits the bill if all you need to do is set simple variables, loops, conditionals and functions. PyMite is tiny, written in C, uses a static memory pool and can be embedded. It has an extremely limited set of builtin functions that is easy to configure. Similarly, the only standard libraries are partial implementations of string, dict, list and sys. The PyMite VM is part of the python-on-a-chip project, so it was designed to run on microcontrollers, but can run on posix-style desktop systems. The downside is that PyMite is not as extensively de-bugged as other Python implementations.