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

# Manage sandbox lifecycle

> Keep work for later, resume a sandbox, restart it, or delete it.

Idle sandboxes sleep automatically. Use archive when you want to keep a sandbox
for later and release its active slot. Use delete when you are finished with its
files and processes.

Connect to a sandbox you want to manage:

```python theme={null}
from lithosbox import LithosBox

box = LithosBox()
sandbox = box.sandboxes.get("YOUR_SANDBOX_ID")
print(sandbox.info.state)
```

## Leave a sandbox idle

You do not need to send keep-alive requests. An idle sandbox can sleep after about
60 seconds without activity, and a later command or file operation wakes it.
Servers, background jobs, and active connections keep it awake while they are in use.

To sleep a sandbox yourself:

```python theme={null}
slept = sandbox.sleep()
print(slept)
```

A sandbox you sleep and a sandbox the idle policy sleeps are in the same state:
the next command wakes it, so your code does not need to know it was asleep.
`sandbox.wake()` wakes it immediately, which is useful before a burst of work.

`sleep()` returns whether this call put the sandbox to sleep. A busy sandbox —
one running foreground work, background processes, or an exposed port — stays
awake; archive it instead to stop a busy sandbox. Sleeping sandboxes keep their
memory on the host and count toward your organization's active sandbox limit,
and sleep is not a durable checkpoint: use a snapshot or archive to retain
recoverable work.

## Archive and unarchive

Archive a sandbox to save its files, memory, and running processes for later:

```python theme={null}
sandbox.archive()
```

An archived sandbox releases its active slot and retains its saved state. It does
not run commands or serve traffic until you explicitly unarchive it:

```python theme={null}
sandbox.unarchive()
print(sandbox.run("pwd").check().stdout)
```

Processes continue from the saved state. Reconnect external network connections,
and allow exposed services a brief reconnect period. Archiving can take longer
than sleeping, particularly when there is more state to save.

## Reboot an unresponsive sandbox

```python theme={null}
sandbox.reboot()
```

Reboot preserves files but ends processes and shell sessions. Restart any servers
you need afterward. Unarchive an archived sandbox before rebooting it.

## Delete a sandbox

Download results or [save a durable snapshot](/guides/save-restore) before deleting
work you want to keep:

```python theme={null}
sandbox.delete()
box.close()
```

Deletion removes the sandbox's working state. Its ID can no longer be used to
access it, and a repeated delete is safe. Retained snapshots are separate resources;
delete them separately when you no longer need them.

See [Core concepts](/concepts#rest-states) for a comparison of states and
[Recovery](/launch#recovery) for interrupted or unavailable sandboxes.
