Migrate from Modal
Change import modal to import kosa8.compat.modal as modal, set
KOSA8_API_KEY, and your modal.Sandbox code runs on kosa8.
# Before: import modal import kosa8.compat.modal as modal # reads KOSA8_API_KEY app = modal.App.lookup("my-app", create_if_missing=True) sb = modal.Sandbox.create(app=app, image=modal.Image.debian_slim(), timeout=300) p = sb.exec("python3", "-c", "print(6 * 7)") print(p.returncode, p.stdout.read().strip()) # 0 42 sb.terminate()
How it maps#
| Modal | kosa8 Cloud |
|---|---|
Sandbox.create(...) | Create. image from Image.from_registry or debian_slim, timeout the ttl, idle_timeout sleep after idle, cpu and memory a size, Secret.from_name org secrets |
sandbox.exec(*args) | A streamed exec, returned while it runs; stdout iterates lines as they print |
terminate | Delete |
snapshot_filesystem | A snapshot, usable as image= |
filesystem.*, set_tags | The files API, labels |
What is different#
sandbox.execoutput streams as it prints and is not held to 90 s. An entrypoint's stdout is polled about once a second and its stderr arrives when it ends.- With the Python shim (0.7.0 and later) the sandbox is persistent: installed packages, files outside
/workspaceand background processes last between commands (KOSA8_SHIM_PERSISTENT=0turns that off; a plan with no persistent sandboxes left gets a plain one, where only/workspacelasts). Each command is still a new process, socdandexportdo not carry. - Image builds (
pip_install,run_commands), GPUs, volumes and stdin raisekosa8.compat.Unsupported;encrypted_portsandsandbox.tunnels()map to kosa8 previews (HTTPS only, no raw TCP). Install once and keep a snapshot instead. - Modal Functions are not mirrored; kosa8 has its own functions. Only the synchronous Sandbox API (Modal 1.6.4) is mirrored, not
.aio.
Something wrong or missing? Write to contact@kosa8.com.