Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Connect to your sandbox via SSH using a WebSocket proxy
Build the SSH template
// template.ts import { Template, waitForPort } from 'e2b' export const template = Template() .fromUbuntuImage('25.04') .aptInstall(['openssh-server']) .runCmd([ 'curl -fsSL -o /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl', 'chmod a+x /usr/local/bin/websocat', ], { user: 'root' }) .setStartCmd('sudo websocat -b --exit-on-eof ws-l:0.0.0.0:8081 tcp:127.0.0.1:22', waitForPort(8081))
// build.ts import { Template, defaultBuildLogger } from 'e2b' import { template as sshTemplate } from './template' await Template.build(sshTemplate, 'ssh-ready', { cpuCount: 2, memoryMB: 2048, onBuildLogs: defaultBuildLogger(), })
Create a sandbox from the template
import { Sandbox } from 'e2b' const sbx = await Sandbox.create('ssh-ready') console.log(sbx.sandboxId)
Connect from your machine
# Install websocat brew install websocat # Connect to your sandbox ssh -o 'ProxyCommand=websocat --binary -B 65536 - wss://8081-%h.e2b.app' user@<sandbox-id>
┌───────────────────────────────────────────────────────────┐ │ Your Machine │ │ ┌──────────┐ ProxyCommand ┌──────────────────┐ │ │ │ SSH │ ────────────────── │ websocat │ │ │ │ Client │ │ (WebSocket) │ │ │ └──────────┘ └─────────┬────────┘ │ └────────────────────────────────────────────┼──────────────┘ │ wss://8081-<sandbox-id>.e2b.app │ ┌────────────────────────────────────────────┼──────────────┐ │ E2B Sandbox ▼ │ │ ┌──────────────────┐ │ │ │ websocat │ │ │ │ (WS → TCP:22) │ │ │ └─────────┬────────┘ │ │ │ │ │ ┌─────────▼────────┐ │ │ │ SSH Server │ │ │ │ (OpenSSH) │ │ │ └──────────────────┘ │ └───────────────────────────────────────────────────────────┘
Was this page helpful?