[Python-Dev] Sandboxing Python (original) (raw)

Victor Stinner victor.stinner at gmail.com
Thu Mar 1 19:23:47 CET 2012


Hi,

The frozendict discussion switched somewhere to sandboxing, and so I prefer to start a new thread.

There are various ways to implement a sandbox, but I would like to expose here how I implemented pysandbox to have your opinion. pysandbox is written to execute quickly a short untrusted function in a sandbox and then continue the normal execution of the program. It is possible to "enable" the sandbox, but also later to "disable" it. It is written for Python using only one thread and one process.

To create a sandbox, pysandbox uses various protections. The main idea is to create an empty namespace and ensure that it is not possible to use objects added into the namespace for escaping from the sandbox. pysandbox only uses one thread and one process and so it doesn't replace the existing trusted namespace, but create a new one. The security of pysandbox depends on the sandbox namespace sealing.

I don't want to integrate pysandbox in CPython because I am not yet conviced that the approach is secure by design. I am trying to patch Python to help the implementation of Python security modules and of read-only proxies.

You can find below the list of protections implemented in pysandbox. Some of them are implemented in C.

I challenge anymore to break pysandbox! I would be happy if anyone breaks it because it would make it more stronger.

https://github.com/haypo/pysandbox/ http://pypi.python.org/pypi/pysandbox

Namespace

Generic

Remove all builtin symbols not in the whitelist.

Features

import

Filesystem

Exit

Standard input/output

Bytecode

Execute arbitrary bytecode may crash Python, or lead to execution of arbitrary (machine) code.

Victor



More information about the Python-Dev mailing list