The rexec Module (cont)

Example

     # Create a little restricted environment
     import rexec
     class AppletExec(rexec.RExec):
         ok_builtin_modules = ['string','math','time'] 
         ok_posix_names = []
         def r_open(*args):
              # Check filename for special cases
              ...
              raise SystemError, "Go away"
     
     r = AppletExec()
     r.r_exec(appletcode)

Additional comments regarding restricted mode

  • The interpreter runs in restricted mode if the identity of __builtins__ has been changed.
  • Restricted programs can't access the __dict__ attribute of classes and instances.
  • Similar restrictions are placed on other objects to prevent a code from becoming priviledged.
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 115
July 17, 2000, beazley@cs.uchicago.edu
>>>