> For the list of every page, fetch /llms.txt. The API contract is the OpenAPI file linked from the API reference.

# Files, ports, and SSH

Three ways to reach into a running sandbox:

- Files: copy one file, or a whole directory as a tar stream, through Meadow.
- Ports: get a URL for a port the sandbox listens on. Traffic goes straight to the provider.
- SSH: get a login for a normal SSH client. Traffic goes straight to the provider.

Next step: upload a file with the first sample. Ports and SSH must be asked for when the sandbox is created.

The samples use `$SANDBOX` for the sandbox ID.

## Files

`path` is an absolute path inside the sandbox.

### Upload a file

```bash
curl -sS -X PUT "$MEADOW_BASE_URL/v1/sandboxes/$SANDBOX/files?path=/work/config.yaml" \
  -H "Authorization: Bearer $MEADOW_API_KEY" \
  -H "Content-Type: application/octet-stream" \
  --data-binary @config.yaml -w '%{http_code}\n'
```

```text
204
```

Missing parent directories are created.

The file belongs to the image's default user, which is `root` for most images, and has mode 0644. Directories Meadow creates are `root` with mode 0755. There is no parameter for the owner or the mode: `&mode=755` is ignored and the call still returns 204. Checked with `ls -ln` on Daytona and Modal:

```text
-rw-r--r-- 1 0 0 18 Nov 24 00:05 /work/run.sh
```

A command you run with `"user"` set to another user can read the file. It cannot write beside it, and it cannot execute a script you uploaded:

```text
touch: cannot touch '/work/task/out.txt': Permission denied
```

Fix the owner or the mode with one [exec](/run-sandboxes/running-commands) call, which runs as `root` by default:

```bash
curl -sS -X POST "$MEADOW_BASE_URL/v1/sandboxes/$SANDBOX/exec" \
  -H "Authorization: Bearer $MEADOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"command": "chown -R nobody /work/task && chmod +x /work/run.sh"}'
```

After that the same `touch` as `nobody` exited 0. You can also create the directory for that user in the [image](/run-sandboxes/images-and-build-contexts) and upload into it, then `chown` only the new files.

### Download a file

```bash
curl -sS "$MEADOW_BASE_URL/v1/sandboxes/$SANDBOX/files?path=/work/config.yaml" \
  -H "Authorization: Bearer $MEADOW_API_KEY" -o config.yaml
```

The body is the file, with `content-type: application/octet-stream`.

### Upload a directory

Pack the directory as a tar and add `archive=tar`. Entries are unpacked into `path`, with no top-level folder.

```bash
COPYFILE_DISABLE=1 tar -cf task.tar -C task .

curl -sS -X PUT "$MEADOW_BASE_URL/v1/sandboxes/$SANDBOX/files?path=/work/task&archive=tar" \
  -H "Authorization: Bearer $MEADOW_API_KEY" \
  -H "Content-Type: application/octet-stream" \
  --data-binary @task.tar -w '%{http_code}\n'
```

```text
204
```

`COPYFILE_DISABLE=1` matters on macOS. Without it, `tar` adds `._` files beside each of yours and they are unpacked in the sandbox.

The tar is plain, not gzipped. A gzipped tar returns 400 `invalid tar archive` and nothing is unpacked. See [Limits and errors](#limits-and-errors).

Entries keep the mode and the numeric owner stored in the tar. A tar made on a Mac unpacks as uid 501, which is no user in most images:

```text
drwxr-xr-x 2 501 0 28 Nov 24 00:05 data
-rw-r--r-- 1 501 0 27 Nov 24 00:05 run.py
```

Run `chown -R` with exec after the upload, as above, or set the owner when you build the tar, as the Python sample below does.

Checking the result with exec:

```json
{"exit_code": 0, "stderr": "", "stdout": "/work/config.yaml\n/work/task/data/in.csv\n/work/task/run.py\n", "timed_out": false}
```

The same upload from Python, with the tar built in memory and every entry owned by `root`. It then downloads the directory again and unpacks it:

```python
import io
import os
import tarfile

import requests

BASE = os.environ["MEADOW_BASE_URL"]
HEADERS = {"Authorization": f"Bearer {os.environ['MEADOW_API_KEY']}"}
SANDBOX = os.environ["SANDBOX"]


def as_root(entry: tarfile.TarInfo) -> tarfile.TarInfo:
    entry.uid = entry.gid = 0
    entry.uname = entry.gname = ""
    return entry


buffer = io.BytesIO()
with tarfile.open(fileobj=buffer, mode="w") as archive:
    archive.add("task", arcname=".", filter=as_root)

resp = requests.put(
    f"{BASE}/v1/sandboxes/{SANDBOX}/files",
    headers={**HEADERS, "Content-Type": "application/octet-stream"},
    params={"path": "/work/task", "archive": "tar"},
    data=buffer.getvalue(),
    timeout=120,
)
print("upload", resp.status_code)

resp = requests.get(
    f"{BASE}/v1/sandboxes/{SANDBOX}/files",
    headers=HEADERS,
    params={"path": "/work/task", "archive": "tar"},
    timeout=120,
)
resp.raise_for_status()
with tarfile.open(fileobj=io.BytesIO(resp.content)) as archive:
    print(sorted(archive.getnames()))
    archive.extractall("task-out", filter="data")
```

```text
upload 204
['.', './data', './data/in.csv', './run.py']
```

`filter="data"` makes `extractall` reject links and paths that leave the target folder. It needs Python 3.12, or a recent patch release of 3.10 or 3.11.

### Download a directory

```bash
curl -sS "$MEADOW_BASE_URL/v1/sandboxes/$SANDBOX/files?path=/work/task&archive=tar" \
  -H "Authorization: Bearer $MEADOW_API_KEY" -o task-out.tar
tar -tvf task-out.tar
```

```text
drwx------  0 501    root        0 Nov 23 14:20 ./
-rw-------  0 501    root       27 Nov 23 14:20 ./run.py
drwx------  0 501    root        0 Nov 23 14:20 ./data/
-rw-------  0 501    root        8 Nov 23 14:20 ./data/in.csv
```

Entries are relative to `path`, so unpack into a directory you made. A sandbox runs code you may not trust. Check an archive before you unpack it into a place that matters, and be careful with symlinks in it.

### Limits and errors

| Limit | Value |
| --- | --- |
| One upload | 100 MiB. A larger body returns 413 with `error.code` `request_too_large` and the message `request body too large` (seen on the hosted beta on 2026-11-24). |
| One entry in an uploaded tar | 100 MiB |
| `path` | Absolute, at most 4096 bytes, no `..` segment |

A 40 MiB file took about 4.5 seconds to upload and 4.3 seconds to download on Daytona. For anything larger than 100 MiB, split it, or have the sandbox download it.

There are no calls to list, stat, make, or remove a path. Use [exec](/run-sandboxes/running-commands) with `ls`, `test`, `mkdir`, and `rm`.

| Status | Message | Cause |
| --- | --- | --- |
| 404 | `file not found` | Nothing at `path`. |
| 404 | `directory not found` | Nothing at `path`, with `archive=tar`. |
| 400 | `path is a directory; use archive=tar to download a directory` | |
| 400 | `path must be an absolute path` | |
| 400 | `path must not contain path traversal segments` | `path` has a `..`. |
| 400 | `invalid tar archive` | The body is not a tar, it is gzipped, it is cut short, or its length is not a multiple of 512 bytes. Meadow checks the whole body before the sandbox unpacks it, so no file was written. On Modal the empty target directory may exist. Send a plain tar. Seen on both providers: after the 400, Daytona had no target directory and Modal had an empty one. |
| 400 | `the sandbox could not unpack the tar archive; some entries may have been written` | The archive passed Meadow's check and the `tar` program in the sandbox failed, for example on a full disk or a directory it may not write to. Some entries may be there. Remove the directory with exec before you retry. Not seen on the hosted beta. |
| 400 | `cannot create target directory` | The target path of a tar upload cannot be made, for example under a read-only path. Seen on both providers with a target under `/proc`. Pick a path the sandbox can write to. |
| 400 | `archive must be tar` | `archive` takes one value. |
| 409 | `sandbox is not running` | |
| 502 | `sandbox_unreachable` in `error.code` | The provider answered "not found" for a sandbox it still reports as running. Nothing was changed. Retry after `Retry-After` seconds. Port and ssh calls return it too. On the hosted beta since 2026-11-27. |

## Ports

List the ports in `ports` when you create the sandbox. A port cannot be opened later.

```bash
curl -sS -X POST "$MEADOW_BASE_URL/v1/sandboxes?wait=true" \
  -H "Authorization: Bearer $MEADOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"image": "python:3.12-slim", "ports": [8000], "timeout_seconds": 900}'
```

Start something that listens. A server is long-running, so start it in the background:

```bash
curl -sS -X POST "$MEADOW_BASE_URL/v1/sandboxes/$SANDBOX/exec" \
  -H "Authorization: Bearer $MEADOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"command": "cd /tmp && echo hello > index.html && python -m http.server 8000", "background": true}'
```

Ask for the address:

```bash
curl -sS "$MEADOW_BASE_URL/v1/sandboxes/$SANDBOX/ports/8000" \
  -H "Authorization: Bearer $MEADOW_API_KEY"
```

On Daytona:

```json
{
  "expires_at": null,
  "headers": {"X-Daytona-Preview-Token": "<token>"},
  "port": 8000,
  "url": "https://8000-<id>.daytonaproxy01.net"
}
```

On Modal:

```json
{
  "expires_at": "2026-11-24T22:28:36Z",
  "headers": {"Authorization": "Bearer <token>"},
  "port": 8000,
  "url": "https://<id>.w.modal.host"
}
```

Send every header in `headers` with every request to `url`:

```bash
curl -sS "https://8000-<id>.daytonaproxy01.net/index.html" -H "X-Daytona-Preview-Token: <token>"
```

With the headers the request returned 200 on both providers. Without them it returned 401 on both.

The URL and headers together are a credential. Anyone who has them can reach the port until `expires_at`. Call the route again for a fresh one.

| | Daytona | Modal |
| --- | --- | --- |
| Header | `X-Daytona-Preview-Token` | `Authorization: Bearer ...` |
| `expires_at` | `null` | 24 hours after the call |
| No header needed | Set `provider.options.daytona.public` to `true` at create. The URL alone then works, for anyone. | Not available |
| With `network.block_all` | Works | Not possible. Modal is skipped at create with an `unsupported` attempt. Use an allowlist. See [Network rules](/run-sandboxes/network-rules). |

Traffic does not pass through Meadow. Only HTTP has been checked. WebSocket has not been checked on either provider. For other protocols, forward a port over SSH.

A port that was not declared returns 400:

```json
{"error":{"code":"invalid_request","message":"port was not declared at sandbox create","type":"invalid_request"},"request_id":"req_0000a6ac"}
```

## SSH

Set `"ssh": true` when you create the sandbox. It cannot be turned on later. Then ask for a login:

```bash
curl -sS -X POST "$MEADOW_BASE_URL/v1/sandboxes/$SANDBOX/ssh" \
  -H "Authorization: Bearer $MEADOW_API_KEY" -o ssh.json
chmod 600 ssh.json
```

The response is a credential. Keep it out of logs. Each call returns a new one.

A sandbox created without `ssh` returns 404 with a `code` you can test for:

```json
{"error":{"code":"ssh_not_enabled","message":"sandbox was not created with ssh: true","type":"not_found"},"request_id":"req_00002a89"}
```

### On Daytona

```json
{
  "expires_at": "2026-11-23T23:26:59.373Z",
  "host": "ssh.app.daytona.io",
  "host_key": null,
  "port": 22,
  "private_key": null,
  "username": "<token>"
}
```

The credential is the `username`. There is no key and no password:

```bash
ssh -p "$(jq -r .port ssh.json)" "$(jq -r .username ssh.json)@$(jq -r .host ssh.json)" 'echo ssh ok; id -un'
```

```text
ssh ok
root
```

- `host_key` is null, so your client asks you to accept the host key the first time. In a script, add `-o StrictHostKeyChecking=accept-new`.
- The login expires at `expires_at`, one hour after the call in our runs.
- Any image works. Nothing is installed in the sandbox.

### On Modal

```json
{
  "expires_at": "2026-11-23T22:43:31.761Z",
  "host": "<id>.modal.host",
  "host_key": "ssh-ed25519 AAAA...",
  "port": 2222,
  "private_key": "-----BEGIN OPENSSH PRIVATE KEY-----\n...",
  "username": "root"
}
```

Write the key and the host key to files, then connect:

```bash
jq -r .private_key ssh.json > sandbox_key && chmod 600 sandbox_key
echo "[$(jq -r .host ssh.json)]:$(jq -r .port ssh.json) $(jq -r .host_key ssh.json)" > sandbox_known_hosts

ssh -i sandbox_key -o IdentitiesOnly=yes \
  -o UserKnownHostsFile=sandbox_known_hosts -o StrictHostKeyChecking=yes \
  -p "$(jq -r .port ssh.json)" "root@$(jq -r .host ssh.json)" 'echo ssh ok; id -un'
```

```text
ssh ok
root
```

- Meadow runs an SSH server inside the sandbox, as `root`. The login user is `root`.
- If the image has no `sshd`, Meadow installs `openssh-server` with `apt-get` while the sandbox is created. A create with `ssh: true` took about 6 seconds on an image built from `python:3.12-slim` without `sshd`, against about 1 second for a create without `ssh`. Put `openssh-server` in the image to skip the install.
- `expires_at` is the sandbox's own end. Each call adds a key that works until the sandbox ends. There is no call to revoke one. Delete the sandbox to end access.

A Modal create with `ssh: true` fails when the server cannot be set up, and the attempt says why. On an image without `apt-get`, such as `alpine:3.20`:

```json
{
  "status": "failed",
  "failure_reason": "all_providers_failed",
  "attempts": [
    {
      "detail": "modal ssh needs sshd in the image or apt-get to install openssh-server; the image has neither",
      "duration_ms": 1780,
      "outcome": "unsupported",
      "provider": "modal"
    }
  ]
}
```

With `network.block_all` and no `sshd` in the image, the detail is `modal ssh could not install openssh-server with apt-get; the sandbox needs network access to the package mirror`.

With `network.block_all` and `ssh: true`, Modal is skipped at create. The attempt reads `unsupported` with the detail `modal blocks inbound connections too when network.block_all is set, so ports and ssh cannot be reached; use allow_domains or allow_cidrs, or daytona`. When your route allows Daytona, the sandbox is created there. Both outcomes were seen on the hosted beta.

SSH and `block_all` do not work together on Modal. Use a domain or CIDR allowlist there, or use Daytona, where SSH works with `block_all`.

### Forward a port and copy files

`ssh -L` reaches any port in the sandbox, declared or not. This worked on both providers:

```bash
ssh -N -L 18000:127.0.0.1:8000 -p "$(jq -r .port ssh.json)" "$(jq -r .username ssh.json)@$(jq -r .host ssh.json)"
```

On Modal add the `-i` and `-o` flags from the sample above.

`scp` works on both providers with OpenSSH 9 or newer on your side, which copies over SFTP. On Daytona with `python:3.12-slim` and OpenSSH 10.3, `scp` copied a file in each direction. The old protocol needs the `scp` program in the image: `scp -O` failed there with `scp: not found`. On Modal `openssh-server` brings that program. The [files calls](#files) work on every image.

### Summary

| | Daytona | Modal |
| --- | --- | --- |
| Credential | A token in `username` | `private_key` |
| `host_key` | `null` | The server's key, for pinning |
| Login user | The image's user | `root` |
| Expires | About one hour after the call | When the sandbox ends |
| Image needs | Nothing | `sshd`, or `apt-get` and network at create |
| With `network.block_all` | Works | Not possible: Modal is skipped at create |

More in [Known limits](/reference/known-limits#running-sandboxes).

## API reference

Operations on this page: [`uploadFile`](/reference/api-reference#uploadfile), [`downloadFile`](/reference/api-reference#downloadfile), [`getPort`](/reference/api-reference#getport), [`createSshAccess`](/reference/api-reference#createsshaccess), [`createSandbox`](/reference/api-reference#createsandbox).