# 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.

**Python**

```
# 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)` | Exec; the process has finished when it returns |
| `terminate` | Delete |
| `snapshot_filesystem` | A snapshot, usable as `image=` |
| `filesystem.*`, `set_tags` | The files API, labels |

## What is different

- Output arrives when a command ends, not line by line. For live output use kosa8's [streamed exec](https://docs.kosa8.com/concepts/exec/#streaming).

- Image builds (`pip_install`, `run_commands`), GPUs, volumes, tunnels and stdin raise `kosa8.compat.Unsupported`. Install once and keep a [snapshot](https://docs.kosa8.com/concepts/snapshots/) instead.

- Modal Functions are not mirrored; kosa8 has its own [functions](https://docs.kosa8.com/serverless/functions/). Only the synchronous Sandbox API (Modal 1.6.4) is mirrored, not `.aio`.

---
Source: https://docs.kosa8.com/migrate/modal/
