Slide 1

Slide 1 text

Building and breaking a Python sandbox

Slide 2

Slide 2 text

Director Organizer @jessicamckellar http://jesstess.com

Slide 3

Slide 3 text

Why? • Learning a language • Providing a hosted scratch pad • Distributed computation • Inspecting running processes safely

Slide 4

Slide 4 text

Examples in the wild • Seattle’s peer-to-peer computing network • Google App Engine’s Python shell • Codecademy’s empythoned • CheckIO.org’s online coding game

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Building a sandbox • Language-level sandboxing (pysandbox) • OS-level sandboxing (PyPy’s sandbox)

Slide 7

Slide 7 text

Question: How do we execute arbitrary code?

Slide 8

Slide 8 text

How do we execute arbitrary code? exec: compiles and evaluates statements >>> exec "print 'Hello world'" Hello world eval: compiles and evaluates expressions >>> eval("1 + 2") 3

Slide 9

Slide 9 text

class Sandbox(object): def execute(self, code_string): exec code_string sandbox.py

Slide 10

Slide 10 text

from sandbox import Sandbox s = Sandbox() code = """ print "Hello world!" """ s.execute(code) test_sandbox.py

Slide 11

Slide 11 text

$ python test_sandbox.py Hello world! from sandbox import Sandbox s = Sandbox() code = """ print "Hello world!" """ s.execute(code)

Slide 12

Slide 12 text

What should we disallow?

Slide 13

Slide 13 text

What should we disallow? • Resource exhaustion • Information disclosure • Running unexpected services • Disabling/quitting/erroring out of the sandbox

Slide 14

Slide 14 text

from sandbox import Sandbox s = Sandbox() code = """ file("test.txt", "w").write("Kaboom!\\n") """ s.execute(code)

Slide 15

Slide 15 text

What is file?

Slide 16

Slide 16 text

>>> __builtins__.__dict__.keys() ['bytearray', 'IndexError', 'all', 'help', 'vars', 'SyntaxError', 'unicode', 'UnicodeDecodeError', 'memoryview', 'isinstance', 'copyright', 'NameError', 'BytesWarning', 'dict', 'input', 'oct', 'bin', 'SystemExit', 'StandardError', 'format', 'repr', 'sorted', 'False', 'RuntimeWarning', 'list', 'iter', 'reload', 'Warning', '__package__', 'round', 'dir', 'cmp', 'set', 'bytes', 'reduce', 'intern', 'issubclass', 'Ellipsis', 'EOFError', 'locals', 'BufferError', 'slice', 'FloatingPointError', 'sum', 'getattr', 'abs', 'exit', 'print', 'True', 'FutureWarning', 'ImportWarning', 'None', 'hash', 'ReferenceError', 'len', 'credits', 'frozenset', '__name__', 'ord', 'super', '_', 'TypeError', 'license', 'KeyboardInterrupt', 'UserWarning', 'filter', 'range', 'staticmethod', 'SystemError', 'BaseException', 'pow', 'RuntimeError', 'float', 'MemoryError', 'StopIteration', 'globals', 'divmod', 'enumerate', 'apply', 'LookupError', 'open', 'quit', 'basestring', 'UnicodeError', 'zip', 'hex', 'long', 'next', 'ImportError', 'chr', 'xrange', 'type', '__doc__', 'Exception', 'tuple', 'UnicodeTranslateError', 'reversed', 'UnicodeEncodeError', 'IOError', 'hasattr', 'delattr', 'setattr', 'raw_input', 'SyntaxWarning', 'compile', 'ArithmeticError', 'str', 'property', 'GeneratorExit', 'int', '__import__', 'KeyError', 'coerce', 'PendingDeprecationWarning', 'file', 'EnvironmentError', 'unichr', 'id', 'OSError', 'DeprecationWarning', 'min', 'UnicodeWarning', 'execfile', 'any', 'complex', 'bool', 'ValueError', 'NotImplemented', 'map', 'buffer', 'max', 'object', 'TabError', 'callable', 'ZeroDivisionError', 'eval', '__debug__', 'IndentationError', 'AssertionError', 'classmethod', 'UnboundLocalError', 'NotImplementedError', 'AttributeError', 'OverflowError']

Slide 17

Slide 17 text

>>> __builtins__.__dict__.keys() ['bytearray', 'IndexError', 'all', 'help', 'vars', 'SyntaxError', 'unicode', 'UnicodeDecodeError', 'memoryview', 'isinstance', 'copyright', 'NameError', 'BytesWarning', 'dict', 'input', 'oct', 'bin', 'SystemExit', 'StandardError', 'format', 'repr', 'sorted', 'False', 'RuntimeWarning', 'list', 'iter', 'reload', 'Warning', '__package__', 'round', 'dir', 'cmp', 'set', 'bytes', 'reduce', 'intern', 'issubclass', 'Ellipsis', 'EOFError', 'locals', 'BufferError', 'slice', 'FloatingPointError', 'sum', 'getattr', 'abs', 'exit', 'print', 'True', 'FutureWarning', 'ImportWarning', 'None', 'hash', 'ReferenceError', 'len', 'credits', 'frozenset', '__name__', 'ord', 'super', '_', 'TypeError', 'license', 'KeyboardInterrupt', 'UserWarning', 'filter', 'range', 'staticmethod', 'SystemError', 'BaseException', 'pow', 'RuntimeError', 'float', 'MemoryError', 'StopIteration', 'globals', 'divmod', 'enumerate', 'apply', 'LookupError', 'open', 'quit', 'basestring', 'UnicodeError', 'zip', 'hex', 'long', 'next', 'ImportError', 'chr', 'xrange', 'type', '__doc__', 'Exception', 'tuple', 'UnicodeTranslateError', 'reversed', 'UnicodeEncodeError', 'IOError', 'hasattr', 'delattr', 'setattr', 'raw_input', 'SyntaxWarning', 'compile', 'ArithmeticError', 'str', 'property', 'GeneratorExit', 'int', '__import__', 'KeyError', 'coerce', 'PendingDeprecationWarning', 'file', 'EnvironmentError', 'unichr', 'id', 'OSError', 'DeprecationWarning', 'min', 'UnicodeWarning', 'execfile', 'any', 'complex', 'bool', 'ValueError', 'NotImplemented', 'map', 'buffer', 'max', 'object', 'TabError', 'callable', 'ZeroDivisionError', 'eval', '__debug__', 'IndentationError', 'AssertionError', 'classmethod', 'UnboundLocalError', 'NotImplementedError', 'AttributeError', 'OverflowError']

Slide 18

Slide 18 text

How do we disallow execution of problematic builtins?

Slide 19

Slide 19 text

Idea: keyword blacklist

Slide 20

Slide 20 text

class Sandbox(object): def execute(self, code_string): keyword_blacklist = ["file", "quit", "eval", "exec"] for keyword in keyword_blacklist: if keyword in code_string: raise ValueError("Blacklisted") exec code_string Idea: keyword blacklist

Slide 21

Slide 21 text

from sandbox import Sandbox s = Sandbox() code = """ file("test.txt", "w").write("Kaboom!\\n") """ s.execute(code) Testing: keyword blacklist

Slide 22

Slide 22 text

from sandbox import Sandbox s = Sandbox() code = """ file("test.txt", "w").write("Kaboom!\\n") """ s.execute(code) $ python test_sandbox.py Traceback (most recent call last): File "test_sandbox.py", line 11, in s.execute(code) File "/Users/jesstess/Desktop/sandbox/ sandbox.py", line 86, in execute raise ValueError("Blacklisted") ValueError: Blacklisted Testing: keyword blacklist

Slide 23

Slide 23 text

How can we get around a keyword blacklist?

Slide 24

Slide 24 text

Circumvention idea: encryption

Slide 25

Slide 25 text

Circumvention idea: encryption func = __builtins__["file"] func("test.txt", "w").write("Kaboom!\n")

Slide 26

Slide 26 text

Circumvention idea: encryption func = __builtins__["file"] func("test.txt", "w").write("Kaboom!\n") func = __builtins__["svyr".decode("rot13")] func("test.txt", "w").write("Kaboom!\n")

Slide 27

Slide 27 text

from sandbox import Sandbox s = Sandbox() code = """ func = __builtins__["svyr".decode("rot13")] func("test.txt", "w").write("Kaboom!\\n") """ s.execute(code) Testing: keyword blacklist Kaboom

Slide 28

Slide 28 text

Observation: if I can get a reference to something bad, I can invoke it.

Slide 29

Slide 29 text

How can we remove all references to problematic builtins?

Slide 30

Slide 30 text

Idea: builtins whitelist

Slide 31

Slide 31 text

builtins_whitelist = set(( # exceptions 'ArithmeticError', 'AssertionError', 'AttributeError', ... # constants 'False', 'None', 'True', ... # types 'basestring', 'bytearray', 'bytes', 'complex', 'dict', ... # functions '__import__', 'abs', 'all', 'any', 'apply', 'bin', 'bool', ... # block: eval, execfile, file, quit, exit, reload, etc. ))

Slide 32

Slide 32 text

import sys main = sys.modules["__main__"].__dict__ orig_builtins = main["__builtins__"].__dict__ builtins_whitelist = set(( ... )) for builtin in orig_builtins.keys(): if builtin not in builtins_whitelist: del orig_builtins[builtin]

Slide 33

Slide 33 text

from sandbox import Sandbox s = Sandbox() code = """ file("test.txt", "w").write("Kaboom!\\n") """ s.execute(code) Testing: builtins whitelist

Slide 34

Slide 34 text

from sandbox import Sandbox s = Sandbox() code = """ file("test.txt", "w").write("Kaboom!\\n") """ s.execute(code) $ python test_sandbox.py Traceback (most recent call last): File "test_sandbox.py", line 9, in s.execute(code) ... File "", line 2, in NameError: name 'file' is not defined Testing: builtins whitelist

Slide 35

Slide 35 text

Circumvention idea: import something dangerous

Slide 36

Slide 36 text

from sandbox import Sandbox s = Sandbox() code = """ import os fd = os.open("test.txt", os.O_CREAT|os.O_WRONLY) os.write(fd, "Kaboom!\\n") """ s.execute(code) Testing: builtins whitelist Kaboom

Slide 37

Slide 37 text

How do we disallow problematic imports?

Slide 38

Slide 38 text

Idea: import whitelist

Slide 39

Slide 39 text

Idea: import whitelist How does importing a module work in Python?

Slide 40

Slide 40 text

>>> importer = __builtins__.__dict__.get("__import__") >>> os = importer("os") >>> os >>> os.getcwd() '/Users/jesstess/Desktop/sandbox' Idea: import whitelist How does importing a module work in Python?

Slide 41

Slide 41 text

Idea: import whitelist What is the expected function signature for the importer?

Slide 42

Slide 42 text

>>> help(__builtins__.__dict__["__import__"]) __import__(...) __import__(name, globals={}, locals={}, fromlist=[], level=-1) -> module Idea: import whitelist What is the expected function signature for the importer?

Slide 43

Slide 43 text

Idea: import whitelist Cool, let’s write our own importer:

Slide 44

Slide 44 text

>>> def my_importer(module_name, globals={}, ... locals={}, fromlist=[], ... level=-1): ... print "Using my importer!" ... return __import__(module_name, globals, ... locals, fromlist, level) ... >>> os = my_importer("os") Using my importer! >>> os.getcwd() '/Users/jesstess/Desktop/sandbox' Idea: import whitelist Cool, let’s write our own importer:

Slide 45

Slide 45 text

def _safe_import(__import__, module_whitelist): def safe_import(module_name, globals={}, locals={}, fromlist=[], level=-1): ! if module_name in module_whitelist: return __import__(module_name, ! ! ! ! ! ! ! ! ! ! ! ! globals, locals, fromlist, level) else: raise ImportError( "Blocked import of %s" ( module_name,)) return safe_import

Slide 46

Slide 46 text

import sys main = sys.modules["__main__"].__dict__ orig_builtins = main["__builtins__"].__dict__ for builtin in orig_builtins.keys(): if builtin not in builtins_whitelist: del original_builtins[builtin] safe_modules = ["string", "re"] orig_builtins["__import__"] = _safe_import( __import__, safe_modules)

Slide 47

Slide 47 text

from sandbox import Sandbox s = Sandbox() code = """ import os fd = os.open("test.txt", os.O_CREAT|os.O_WRONLY) os.write(fd, "Kaboom!\\n") """ s.execute(code) Testing: import whitelist

Slide 48

Slide 48 text

from sandbox import Sandbox s = Sandbox() code = """ import os fd = os.open("test.txt", os.O_CREAT|os.O_WRONLY) os.write(fd, "Kaboom!\\n") """ s.execute(code) Testing: import whitelist $ python test_sandbox.py Traceback (most recent call last): File "test_sandbox.py", line 11, in ... raise ImportError("Blocked import of %s" % (module_name,)) ImportError: Blocked import of os

Slide 49

Slide 49 text

Circumvention idea: modifying builtins

Slide 50

Slide 50 text

Idea: make builtins read-only

Slide 51

Slide 51 text

How can we make an object read-only in Python?

Slide 52

Slide 52 text

class ReadOnlyBuiltins(dict): def __delitem__(self, key): ValueError("Read-only!") def pop(self, key, default=None): ValueError("Read-only!") def popitem(self): ValueError("Read-only!") ... def setdefault(self, key, value): ValueError("Read-only!") def __setitem__(self, key, value): ValueError("Read-only!") def update(self, dict, **kw): ValueError("Read-only!")

Slide 53

Slide 53 text

main = sys.modules["__main__"].__dict__ orig_builtins = main["__builtins__"].__dict__ for builtin in orig_builtins.keys(): if builtin not in builtins_whitelist: del original_builtins[builtin] safe_modules = ["string", "re"] orig_builtins["__import__"] = _safe_import( __import__, safe_modules) safe_builtins = ReadOnlyBuiltins( original_builtins) main["__builtins__"] = safe_builtins

Slide 54

Slide 54 text

Observation redux: if I can get a reference to something bad, I can invoke it.

Slide 55

Slide 55 text

Circumvention idea: exploiting the inheritance hierarchy

Slide 56

Slide 56 text

>>> dir([]) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', ...] >>> [].__class__ What can we find out about an object’s base classes?

Slide 57

Slide 57 text

>>> [].__class__ >>> [].__class__.__bases__ (,) >>> [].__class__.__bases__[0] What can we find out about an object’s base classes? list subclasses object

Slide 58

Slide 58 text

>>> [].__class__.__subclasses__() [] >>> int.__subclasses__() [] >>> basestring.__subclasses__() [, ] What can we find out about an object’s subclasses? subclasses of basestring

Slide 59

Slide 59 text

>>> [].__class__.__bases__ (,) >>> [].__class__.__bases__[0] >>> [].__class__.__bases__[0].__subclasses__() [, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ] All of the subclasses of object!

Slide 60

Slide 60 text

>>> [].__class__.__bases__ (,) >>> [].__class__.__bases__[0] >>> obj_class = [].__class__.__bases__[0] >>> for c in obj_class.__subclasses__(): ... print c.__name__ ... wrapper_descriptor instance ellipsis member_descriptor file PyCapsule cell callable-iterator iterator ...

Slide 61

Slide 61 text

>>> [].__class__.__bases__ (,) >>> [].__class__.__bases__[0] >>> obj_class = [].__class__.__bases__[0] >>> for c in obj_class.__subclasses__(): ... print c.__name__ ... wrapper_descriptor instance ellipsis member_descriptor file PyCapsule cell callable-iterator iterator ... !!!

Slide 62

Slide 62 text

from sandbox import Sandbox s = Sandbox() code = """ obj_class = [].__class__.__bases__[0] obj_subclasses = dict((elt.__name__, elt) for \ elt in obj_class.__subclasses__()) func = obj_subclasses["file"] func("text.txt", "w").write("Kaboom!\\n") """ s.execute(code) Testing: read-only builtins Kaboom

Slide 63

Slide 63 text

Idea: don’t expose dangerous implementation details

Slide 64

Slide 64 text

>>> type.__bases__ (,) >>> del type.__bases__ Let’s delete __bases__ and __subclasses__

Slide 65

Slide 65 text

>>> type.__bases__ (,) >>> del type.__bases__ Traceback (most recent call last): File "", line 1, in TypeError: can't set attributes of built- in/extension type 'type' Let’s delete __bases__ and __subclasses__ Imposed by the underlying C implementation!

Slide 66

Slide 66 text

from ctypes import pythonapi, POINTER, py_object _get_dict = pythonapi._PyObject_GetDictPtr _get_dict.restype = POINTER(py_object) _get_dict.argtypes = [py_object] del pythonapi, POINTER, py_object def dictionary_of(ob): dptr = _get_dict(ob) return dptr.contents.value cpython.py Let’s delete __bases__ and __subclasses__

Slide 67

Slide 67 text

from cpython import dictionary_of main = sys.modules["__main__"].__dict__ ... safe_builtins = ReadOnlyBuiltins( original_builtins) main["__builtins__"] = safe_builtins type_dict = dictionary_of(type) del type_dict["__bases__"] del type_dict["__subclasses__"]

Slide 68

Slide 68 text

Circumvention idea: would a function by any other name smell as sweet?

Slide 69

Slide 69 text

>>> def foo(): ... print "Meow" ... >>> dir(foo) ['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']

Slide 70

Slide 70 text

>>> def foo(): ... print "Meow" ... >>> dir(foo) ['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name'] ???

Slide 71

Slide 71 text

>>> foo.func_code ", line 1> >>> dir(foo.func_code) ['__class__', '__cmp__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_stacksize', 'co_varnames'] >>> foo.func_code.co_code 'd\x01\x00GHd\x00\x00S'

Slide 72

Slide 72 text

>>> def foo(): ... print "Meow" ... >>> def evil_function(): ... print "Kaboom!" ... >>> foo() Meow

Slide 73

Slide 73 text

>>> def foo(): ... print "Meow" ... >>> def evil_function(): ... print "Kaboom!" ... >>> foo() Meow >>> foo.__setattr__("func_code", evil_function.func_code)

Slide 74

Slide 74 text

>>> def foo(): ... print "Meow" ... >>> def evil_function(): ... print "Kaboom!" ... >>> foo() Meow >>> foo.__setattr__("func_code", evil_function.func_code) >>> foo() Kaboom! Kaboom

Slide 75

Slide 75 text

Idea redux: don’t expose dangerous implementation details

Slide 76

Slide 76 text

from cpython import dictionary_of from types import FunctionType ... type_dict = dictionary_of(type) del type_dict["__bases__"] del type_dict["__subclasses__"] function_dict = dictionary_of(FunctionType) del function_dict["func_code"] Delete func_code

Slide 77

Slide 77 text

Whew. Let’s recap tactics: • Keyword blacklist • Builtins whitelist • Import whitelist • Making important objects read-only (builtins) • Deleting problematic implementation details (__bases__, __subclasses__, func_code) • Deleting the ability to construct arbitrary code objects

Slide 78

Slide 78 text

We have run out of tricks! We’ve implemented 80% of a full-fledged Python sandbox

Slide 79

Slide 79 text

builtins_whitelist = set(( # exceptions 'ArithmeticError', 'AssertionError', 'AttributeError', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'EnvironmentError', 'Exception', 'FloatingPointError','FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError','LookupError', 'MemoryError', 'NameError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError','PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'TabError', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError','UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', # constants 'False', 'None', 'True', '__doc__', '__name__', '__package__', 'copyright', 'license', 'credits', # types 'basestring', 'bytearray', 'bytes', 'complex', 'dict', 'float', 'frozenset', 'int', 'list', 'long', 'object', 'set', 'str', 'tuple', 'unicode', # functions '__import__', 'abs', 'all', 'any', 'apply', 'bin', 'bool', 'buffer', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'delattr', 'dir', 'divmod', 'enumerate', 'filter', 'format', 'getattr', 'globals', 'hasattr', 'hash', 'hex', 'id', 'isinstance', 'issubclass', 'iter', 'len', 'locals', 'map', 'max', 'min', 'next', 'oct', 'ord', 'pow', 'print', 'property', 'range', 'reduce', 'repr', 'reversed', 'round', 'setattr', 'slice', 'sorted', 'staticmethod', 'sum', 'super', 'type', 'unichr', 'vars', 'xrange', 'zip', )) def _safe_import(__import__, module_whitelist): def safe_import(module_name, globals={}, locals={}, fromlist=[], level=-1): if module_name in module_whitelist: return __import__(module_name, globals, locals, fromlist, level) else: raise ImportError("Blocked import of %s" % (module_name,)) return safe_import class ReadOnlyBuiltins(dict): def clear(self): ValueError("Read-only!") def __delitem__(self, key): ValueError("Read-only!") def pop(self, key, default=None): ValueError("Read-only!") def popitem(self): ValueError("Read-only!") def setdefault(self, key, value): ! ValueError("Read-only!") def __setitem__(self, key, value): ValueError("Read-only!") def update(self, dict, **kw): ValueError("Read-only!") class Sandbox(object): def __init__(self): ! import sys ! from types import FunctionType ! from cpython import dictionary_of ! original_builtins = sys.modules["__main__"].__dict__["__builtins__"].__dict__ ! for builtin in original_builtins.keys(): if builtin not in builtins_whitelist: ! ! del sys.modules["__main__"].__dict__["__builtins__"].__dict__[builtin] original_builtins["__import__"] = _safe_import(__import__, ["string", "re"]) safe_builtins = ReadOnlyBuiltins(original_builtins) sys.modules["__main__"].__dict__["__builtins__"] = safe_builtins ! type_dict = dictionary_of(type) ! del type_dict["__bases__"] ! del type_dict["__subclasses__"] ! function_dict = dictionary_of(FunctionType) ! del function_dict["func_code"] def execute(self, code_string): ! exec code_string builtins whitelist import whitelist read-only builtins deleting __bases__, __subclasses_, and func_code

Slide 80

Slide 80 text

What should we disallow? • Resource exhaustion • Information disclosure • Running unexpected services • Disabling/quitting/erroring out of the sandbox

Slide 81

Slide 81 text

Building a sandbox • Language-level sandboxing (pysandbox) • OS-level sandboxing (PyPy’s sandbox)

Slide 82

Slide 82 text

Food for thought

Slide 83

Slide 83 text

Do other languages have these sandboxing concerns?

Slide 84

Slide 84 text

If you were designing a new language, how would you do this?

Slide 85

Slide 85 text

Experiments • How does an alternative Python implementation like PyPy handle these issues? • How does the CPython interpreter compile and run bytecode? • What does the Python stack look like? • How do ctypes work? • How can the operating system help provide a secure environment?

Slide 86

Slide 86 text

Bedtime reading • The full pysandbox implementation: https://github.com/haypo/pysandbox/ • A retrospective on pysandbox’s challenges: https://lwn.net/Articles/574215/ • PyPy’s sandbox implementation: http://pypy.readthedocs.org/en/latest/sandbox.html • How PythonAnywhere’s sandbox works: http://blog.pythonanywhere.com/83/

Slide 87

Slide 87 text

Thank you!

Slide 88

Slide 88 text

Let’s talk! Saturday, 10:20am O’Reilly booth in the Expo Hall Thank you!