Sandboxes
Build an image, run a script in a Chalk sandbox, and terminate the sandbox.
Build an image, upload a local script, run it in a sandbox, and terminate the sandbox when the work is complete:
from chalkcompute import Image, Sandbox
image = (
Image.debian_slim("3.12")
.pip_install(["requests"])
.add_local_file("./script.py", "/app/script.py")
.workdir("/app")
)
sandbox = Sandbox(
image=image,
name="hello-sandbox",
cpu="1",
memory="2Gi",
).run()
result = sandbox.exec("python", "/app/script.py")
print(result.stdout_text)
sandbox.terminate()
Sandbox(...).run() builds the Image, reuses a cached
build when possible, creates the sandbox, and waits for it to become ready.
Local files declared with add_local_file or add_local_dir are uploaded as
part of the image setup.