Skip to navigation

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

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'
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:

-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:

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

Fix the owner or the mode with one exec call, which runs as root by default:

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 and upload into it, then chown only the new files.

Download a file

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.

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

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:

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:

{"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:

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")
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

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

LimitValue
One upload100 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 tar100 MiB
pathAbsolute, 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 with ls, test, mkdir, and rm.

StatusMessageCause
404file not foundNothing at path.
404directory not foundNothing at path, with archive=tar.
400path is a directory; use archive=tar to download a directory
400path must be an absolute path
400path must not contain path traversal segmentspath has a ...
400invalid tar archiveThe 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.
400the sandbox could not unpack the tar archive; some entries may have been writtenThe 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.
400cannot create target directoryThe 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.
400archive must be tararchive takes one value.
409sandbox is not running
502sandbox_unreachable in error.codeThe 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.

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:

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:

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

On Daytona:

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

On Modal:

{
"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:

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.

DaytonaModal
HeaderX-Daytona-Preview-TokenAuthorization: Bearer ...
expires_atnull24 hours after the call
No header neededSet provider.options.daytona.public to true at create. The URL alone then works, for anyone.Not available
With network.block_allWorksNot possible. Modal is skipped at create with an unsupported attempt. Use an allowlist. See 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:

{"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:

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:

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

On Daytona

{
"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:

ssh -p "$(jq -r .port ssh.json)" "$(jq -r .username ssh.json)@$(jq -r .host ssh.json)" 'echo ssh ok; id -un'
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

{
"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:

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'
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:

{
"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:

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 work on every image.

Summary

DaytonaModal
CredentialA token in usernameprivate_key
host_keynullThe server’s key, for pinning
Login userThe image’s userroot
ExpiresAbout one hour after the callWhen the sandbox ends
Image needsNothingsshd, or apt-get and network at create
With network.block_allWorksNot possible: Modal is skipped at create

More in Known limits.

API reference

Operations on this page: uploadFile, downloadFile, getPort, createSshAccess, createSandbox.