> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sailresearch.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Migrate a Modal CPU sandbox to Sailboxes

> Give this guide to your coding agent to move a Modal CPU sandbox to a Sailbox. Modal Functions, GPU inference endpoints, and queues can stay on Modal.

## Sailboxes vs. Modal: sandbox lifetime and memory pricing

A Sailbox has [no fixed lifetime by default](https://docs.sailresearch.com/sailboxes-lifecycle.md). It keeps its workspace when it sleeps. Modal limits each [sandbox to 24 hours](https://modal.com/docs/guide/sandboxes#timeouts). Both platforms let memory use grow. [Sail](https://docs.sailresearch.com/sailboxes-pricing.md#rates) charges \$0.008 per GiB-hour of RAM used. [Modal](https://modal.com/pricing) charges about \$0.024 per GiB-hour. Modal bills for the larger of two amounts: the RAM you request or the RAM you use.

## Create the Sailbox

Install the [Sail Python SDK](https://docs.sailresearch.com/reference/python-sdk.md) on the machine that runs your controller. Run `python -m pip install sail`. Sign in with `sail auth login`. Create one Sailbox per session. This example saves its ID in a local file. In your application, store the ID with the agent session.

```python theme={null}
from pathlib import Path
import sail

app = sail.App.find(name="migration-demo", mint_if_missing=True)
sb = sail.Sailbox.create(app=app, name="modal-worker")
Path("sailbox-id.txt").write_text(sb.sailbox_id)
```

## Transfer files

Modal’s `filesystem.write_text(text, path)` takes the file contents first. Sail’s `fs.write(path, data)` takes the destination first. Run this code from the directory that contains `worker.py` and `job.json`. The example worker reads `/tmp/job.json` and writes `/tmp/result.json` inside the Sailbox. Use the paths your worker needs.

```python theme={null}
sb.fs.write("/tmp/worker.py", Path("worker.py").read_bytes())
sb.fs.write("/tmp/job.json", Path("job.json").read_bytes())
```

Install the worker dependencies in a [Sail image](https://docs.sailresearch.com/sailboxes-images). Export the required files from the Modal Volume, or use storage that both workers can access. A file copy does not preserve how the volume saves changes.

## Run your existing worker

For commands that need only the final output, replace `Sandbox.exec()` with `sb.run()`. This call waits for the command to finish.

```diff theme={null}
- process = sandbox.exec("python3", "/tmp/worker.py")
- print(process.stdout.read())
+ result = sb.run(["python3", "/tmp/worker.py"], check=True)
+ print(result.stdout)
```

Use the [Sail process API](https://docs.sailresearch.com/reference/python-sdk.md) for live logs or interactive input.

## Reconnect after sleep

An idle Sailbox [sleeps automatically by default](https://docs.sailresearch.com/sailboxes-autosleep). Use the saved ID to find the same Sailbox. Read the result file. This operation wakes a sleeping Sailbox.

```python theme={null}
from pathlib import Path
import sail

sb = sail.Sailbox.get(Path("sailbox-id.txt").read_text().strip())
print(sb.fs.read("/tmp/result.json").decode())
```

Sleep preserves files and memory. [Termination deletes the Sailbox.](https://docs.sailresearch.com/sailboxes-lifecycle.md)

## Check the worker output

Run your worker with the same input on Modal and on Sail. Compare the command output and the files from both runs.
