---
title: "SSH into a sandbox: shell, scp and tunnels · Pethost"
description: "Plain ssh, scp, sftp and ssh -L into any Pethost sandbox, with your key or a one-hour token as the password. A login wakes a paused sandbox."
---

[Agent Sandboxes](https://pethost.dev/sandboxes/) Plain SSH, scp and tunnels

# SSH into any sandbox

The tools you already use, pointed at a sandbox: `ssh` for a shell, `scp` and `sftp` for files, `ssh -L` for a port. There is no SSH server to install, and a login wakes a paused sandbox where it was.

An ssh command to a paused sandbox on port 2222 wakes it and opens a shell; then a file copies over with scp and a port is forwarded with ssh -L.

## 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 k3x9q2m7v1c8p4ra@sbx1.sandboxes.pethost.network -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.

Python

CLI

```
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 k3x9q2m7v1c8p4ra@sbx1.sandboxes.pethost.network -p 2222
```

```
pethost sandbox shell k3x9q2m7v1c8p4ra   # signs in with a token, no key needed
scp -P 2222 results.csv k3x9q2m7v1c8p4ra@sbx1.sandboxes.pethost.network:/home/user/
ssh -p 2222 -N -L 5432:localhost:5432 k3x9q2m7v1c8p4ra@sbx1.sandboxes.pethost.network
```

## 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](https://pethost.dev/sandboxes/preview-urls/) 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.”

[Read the docs](https://pethost.dev/docs/sandboxes/ssh/)

## Questions

**Do I need sshd in my template to SSH into a sandbox?**

No. The server answers SSH and runs your session inside the sandbox, so every template has it, ours or one you saved.

**Which port?**

2222, on the sandbox’s server, as its `ssh_command` says.

**Does an SSH session keep the sandbox awake?**

Yes, while it is open. Once it closes, the sandbox’s idle timers run again: by default it pauses after 5 minutes.

**Can I copy files?**

Yes, with scp or sftp, or through the API: `write_files` for up to 17 MiB, a download or upload link for any size.

**Can a program sign in without a key?**

Yes, with a token from `connect_sandbox` as the password. It lasts an hour unless you ask for up to a day, and revoking the sandbox’s tokens makes it stop working.

## Related

- [A visit to port 3000’s HTTPS address wakes a paused sandbox in 0.2 s and its page appears; a private port answers 200 to a request with its token and 401 to one without. A URL for every port A dev server on port 3000 answers at its own HTTPS address, public or behind a token, and a visit wakes a paused sandbox in about 0.2 s. How it works](https://pethost.dev/sandboxes/preview-urls/)
- [A program calls run_command and the test output streams back; it edits a file in place; it starts a dev server and the call answers once port 5173 listens. Commands, files and a terminal Run a command and wait for its port, stream its output, edit files by exact replacement, open a terminal in the browser: one API call each. How it works](https://pethost.dev/sandboxes/code-execution/)

## Give your agent a computer in 0.15 s

[Start the free trial](https://console.pethost.dev/welcome?kind=sandboxes)

Pethost · Stephan Gomer · NIP 1133096755

Pethost

- [Templates](https://pethost.dev/templates/)
- [About](https://pethost.dev/about/)
- [Docs](https://pethost.dev/docs/)
- [Blog](https://pethost.dev/blog/)
- [API](https://pethost.dev/docs/api/)
- [CLI](https://pethost.dev/docs/cli/)
- [Plugin](https://github.com/pethost-dev/plugin)
- [Terms](https://pethost.dev/terms/)
- [Privacy](https://pethost.dev/privacy/)
- [Refunds](https://pethost.dev/refunds/)
- [support@pethost.dev](mailto:support@pethost.dev)

Databases

- [Postgres](https://pethost.dev/postgres/)
- [Valkey](https://pethost.dev/valkey/)

Agent Sandboxes

- [Sandboxes](https://pethost.dev/sandboxes/)
- [Pricing](https://pethost.dev/sandboxes/#pricing)
- [Docs](https://pethost.dev/docs/sandboxes/)
- [API](https://pethost.dev/docs/sandboxes/api/)

Comparisons

- [Coolify vs Dokploy vs CapRover vs Dokku](https://pethost.dev/blog/coolify-vs-dokploy-vs-caprover-vs-dokku/)
- [Coolify Cloud vs Dokploy Cloud](https://pethost.dev/blog/coolify-cloud-vs-dokploy-cloud/)
- [Railway vs Render vs Fly.io pricing](https://pethost.dev/blog/railway-vs-render-vs-fly-io-pricing/)
- [Managed Docker Compose hosting](https://pethost.dev/blog/managed-docker-compose-hosting/)

Alternatives

- [Railway alternatives](https://pethost.dev/blog/railway-alternatives/)
- [Heroku alternatives](https://pethost.dev/blog/heroku-alternatives/)
- [Dokploy alternatives](https://pethost.dev/blog/dokploy-alternatives/)
- [Coolify alternatives](https://pethost.dev/blog/coolify-alternatives/)
- [Render alternatives](https://pethost.dev/blog/render-alternatives/)
- [Sliplane alternatives](https://pethost.dev/blog/sliplane-alternatives/)
