Sandbox.exec(*command, timeout_secs=..., workdir=..., env=...) runs a process inside an already-running sandbox and returns its result after completion:

from chalkcompute import Image, Sandbox

sandbox = Sandbox(
    image=Image.debian_slim("3.12").workdir("/app"),
    name="hello-sandbox",
).run()

result = sandbox.exec("ls", "-la", "/app", timeout_secs=30)
print(result.stdout_text)
print(result.stderr_text)
print(result.exit_code)

sandbox.terminate()

The result captures stdout and stderr in full and includes the process exit code. Use sandbox.exec_stream(...) for streaming output or sandbox.exec_start(...) when you need interactive stdin and signal handling.

exec, exec_stream, and exec_start require the host compute class. To run work in a k8s sandbox, pass the command as the sandbox’s entrypoint when you create it.