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
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:
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:
Fix the owner or the mode with one exec call, which runs as root by default:
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
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 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:
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:
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:
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
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
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.
Ports
List the ports in ports when you create the sandbox. A port cannot be opened later.
Start something that listens. A server is long-running, so start it in the background:
Ask for the address:
On Daytona:
On Modal:
Send every header in headers with every request to url:
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.
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:
SSH
Set "ssh": true when you create the sandbox. It cannot be turned on later. Then ask for a login:
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:
On Daytona
The credential is the username. There is no key and no password:
host_keyis 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
Write the key and the host key to files, then connect:
- Meadow runs an SSH server inside the sandbox, as
root. The login user isroot. - If the image has no
sshd, Meadow installsopenssh-serverwithapt-getwhile the sandbox is created. A create withssh: truetook about 6 seconds on an image built frompython:3.12-slimwithoutsshd, against about 1 second for a create withoutssh. Putopenssh-serverin the image to skip the install. expires_atis 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:
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:
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
More in Known limits.
API reference
Operations on this page: uploadFile, downloadFile, getPort, createSshAccess, createSandbox.