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

# Export and import

> Take a sandbox's whole filesystem out as one file and restore it in a new sandbox with the same files.

Your sandbox's files are yours to take with you. An export is an ordinary `tar.gz` of the sandbox's filesystem, made
inside the sandbox and downloaded through a signed link; an import uploads that file into another sandbox and unpacks
it. Nothing in the file is specific to Styne, so it also unpacks on any Linux machine.

## Export

```text theme={"theme":"css-variables"}
POST /sandboxes/{id}/exec
{ "argv": ["/bin/sh", "-c", "tar -C / --one-file-system --exclude=./proc --exclude=./sys --exclude=./dev --exclude=./tmp/computer.tar.gz -cpf - . | gzip -1 > /tmp/computer.tar.gz"] }

POST /sandboxes/{id}/files/signed-url
{ "path": "/tmp/computer.tar.gz", "operation": "download", "expiresIn": 900 }
```

Then download the `url` of the answer (see [Files](https://docs.styne.ai/files.md#signed-upload-and-download-urls)): `curl -o computer.tar.gz "<url>"`. To take only
your work, archive a directory instead of `/`, for example `tar -C /home/user -cpf - .`.

## Import

```text theme={"theme":"css-variables"}
POST /sandboxes                      { "templateID": "code" }
POST /sandboxes/{id}/files/signed-url { "path": "/tmp/computer.tar.gz", "operation": "upload", "expiresIn": 900 }
curl -X POST --data-binary @computer.tar.gz -H 'Content-Type: application/octet-stream' "<upload url>"
POST /sandboxes/{id}/exec
{ "argv": ["/bin/sh", "-c", "mkdir -p /home/user && gunzip -c /tmp/computer.tar.gz | tar -C / -xpf - && rm /tmp/computer.tar.gz"] }
```

A new sandbox has no `/home/user` until something creates it, so create the directory you unpack into first.

## What was measured

One `code` sandbox, no other load:

| What | Archive | Pack | Download | Upload | Unpack | Result |
| - | - | - | - | - | - | - |
| `/home/user` with 64 MiB of data | 64 MiB | 1.9 s | 4.2 s | 4.1 s | 0.8 s | same files (SHA-256 of every file), symlink and mode kept |
| the whole filesystem | 161 MiB | 7.0 s | 10.2 s | 9.8 s | 3.5 s | same files |

## What it keeps and what it does not

* Kept: every file's bytes, symbolic links, permission bits.
* Not kept: running processes and memory. The import starts fresh processes on the restored files; to keep a running
  sandbox as it is, pause it instead (see [Timeouts, pause and resume](https://docs.styne.ai/pause-tiers.md)).
* The compare above covers file contents; owners and timestamps are restored by `tar -p` but were not compared.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.