Each sandbox owns a long-lived Python process. Variables, imports, and any
in-memory state survive across run_code calls.
with Sandbox() as s: s.run_code("import pandas as pd") s.run_code("df = pd.read_csv('/data/customers.csv')") s.run_code("print(df.shape)") # pandas + df are both in scope
This is the reason you chose Podflare. Set up expensive state once, then
fork N ways. Each child inherits the parent’s Python REPL + filesystem —
subsequent divergence is copy-on-write isolated.
with Sandbox() as parent: parent.run_code("import json; cfg = {'temp': 0.7}") children = parent.fork(n=3) try: for c in children: print(c.run_code("print(json.dumps(cfg))").stdout) finally: for c in children: c.close()