from nullspace import Sandbox
with Sandbox.create(template="code-interpreter", timeout=120) as sandbox:
# State persists across run_code calls, like notebook cells.
sandbox.run_code("value = 21")
result = sandbox.run_code("value * 2")
print("stateful result:", result.results[0].text)
# Install a package into the live kernel.
sandbox.install_packages(["humanize==4.9.0"])
result = sandbox.run_code("import humanize; print(humanize.intword(1234567))")
print("package output:", "".join(result.logs.stdout).strip())
# Plots come back as PNG data on the result.
plot = sandbox.run_code("""
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 9])
plt.show()
""")
print("plot rendered:", any(r.png for r in plot.results))