How CodeJail sandboxing works
masterCodeJail provides secure execution of untrusted code by leveraging AppArmor for resource confinement and setrlimit for CPU and memory constraints. It operates using two primary layers:
codejail.jail_code: Manages the secure execution of subprocesses. It creates an ephemeral, read-only execution directory containing the submitted code (./jailed_code) and a writable scratch space (./tmp). It spawns a subprocess managed by an AppArmor profile.codejail.safe_exec: A specialized layer for Python execution that emulates Python'sexec()statement. It usesjail_codeto run the code and handles the serialization of theglobalsdictionary to and from the subprocess using JSON.
A sandbox environment (<SANDENV>) typically consists of a read-only virtualenv containing the language runtime (e.g., Python) and required packages, which is shared across sandbox instantiations.