How to SSH into a sandbox
Every sandbox answers SSH on port 2222 of its server, with the sandbox’s id as the user name. Its record carries the whole command, ssh_command, such as ssh [email protected] -p 2222.
Two things sign you in. A public key of the workspace: add yours once with set_ssh_keys or in the web console’s settings, and it opens every sandbox of the workspace. Or a connection token as the password, for a program that holds no key: connect_sandbox makes one for one sandbox, valid for an hour by default and a day at most. pethost sandbox shell makes one for you and signs in with it.
from pathlib import Path
from pethost.sandboxes import Sandboxes
sandboxes = Sandboxes() # reads PETHOST_TOKEN
key = Path("~/.ssh/id_ed25519.pub").expanduser().read_text()
sandboxes.set_ssh_keys(ssh_keys=[key]) # replaces the workspace's keys
box = sandboxes.create_sandbox()
print(box.ssh_command)
# ssh [email protected] -p 2222pethost sandbox shell k3x9q2m7v1c8p4ra # signs in with a token, no key needed
scp -P 2222 results.csv [email protected]:/home/user/
ssh -p 2222 -N -L 5432:localhost:5432 [email protected]How it works
No sshd runs in the sandbox. The server’s SSH gateway speaks SSH to you and talks to the sandbox’s own daemon over the VM’s vsock: your shell, your command or SFTP runs as a process inside the sandbox, and a forwarded port is a tunnel into it. So every template has SSH, yours included, and nothing inside the sandbox listens for it. What you run over SSH is a command like any other: it shows in list_commands and in the sandbox’s events, marked as started by SSH.
The gateway checks your key or token before anything wakes. Then a login wakes a PAUSED sandbox first, its memory and processes as they were, and an open session keeps it awake: with the default lifecycle it pauses again 5 minutes after the last session ends. A STOPPED sandbox refuses the login with “stopped: resume it”, unless its lifecycle wakes it when stopped. Removing a key from the workspace ends that key’s sessions.
Files and tunnels
scp and sftp work as they do with any server. For a file larger than an API call carries, they are the plain way in and out; the API has download and upload links for the same.
ssh -L forwards a port of your computer to a port inside the sandbox: -L 5432:localhost:5432 reaches a Postgres the sandbox keeps to itself, and -L 5173:localhost:5173 opens a dev server in your browser at localhost:5173 without making its port public. This is also how a browser opens a port that is private, since a browser tab cannot send the token a private port asks for. Only the sandbox’s own ports are forwarded, named as localhost; ssh -R is refused.
Limits and prices
Port 2222 on the sandbox’s server; local forwarding only. An SSH channel counts among the 64 calls, streams and links a sandbox serves at once, and a session takes up to 64 environment variables of 32 KiB together. A connection token is a root credential: give it to a program, never put it in a web page. SSH has no price of its own. The sandbox is billed by the second at its size’s price, $0.018 an hour for SMALL (2 vCPU, 4 GiB), and runs while a session is open.
How it compares
On 21 November 2026, E2B reached a sandbox’s shell through a WebSocket proxy. boat.dev has SSH but no pause: after a stop, its docs say a resume within 10 minutes “usually gets the same machine back, with memory and running programs. Do not count on it.”