Documentation Index
Fetch the complete documentation index at: https://docs.celesto.ai/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheSSHClient class provides efficient command execution on guest VMs using persistent SSH connections. It uses paramiko to maintain a single TCP connection that is reused for all commands, eliminating the ~170ms overhead of forking a new ssh process per call.
The connection is established lazily on first use and automatically reconnects if the connection is lost.
Constructor
Guest IP address or hostname.
SSH username for authentication.
SSH port on the guest.
Optional path to an SSH private key file.
Optional password for authentication.
Seconds to wait for the TCP connection.
Login-shell flavor used to wrap commands when
run(..., shell="login") is called:"sh"(default) — POSIX guests. Wraps with$SHELL -lc <quoted>."powershell"— Windows guests. Wraps withpowershell.exe -NoProfile -EncodedCommand <base64>so the command bytes survive Windows OpenSSH’scmd.exelayer unchanged."cmd"— Windows guests where you wantcmd.exe /c "<command>"semantics instead. You are responsible forcmd.exequoting.
shell="raw" on run(...) bypasses the wrap entirely regardless of shell_kind.Properties
connected
True if the connection is active, False otherwise.
Methods
run
Shell command to execute.
Maximum seconds to wait for the command to complete.
Command execution mode:
"login"(default): Run via guest login shell with environment variables loaded"raw": Execute command directly with no shell wrapping
Result object with:
exit_code(int): Exit code of the command (0 = success)stdout(str): Standard output captured from the commandstderr(str): Standard error captured from the commandok(bool): Whether the command succeeded (exit_code == 0)output(str): Convenience alias for stripped stdout
raises
ValueError: If command is emptyOperationTimeoutError: If the command exceeds timeoutSmolVMError: If the SSH connection cannot be established
wait_for_ssh
- TCP probe - Lightweight
socket.connect()calls (~1ms each) to detect when sshd is listening - Paramiko connect - Full SSH handshake + auth. The resulting connection is kept open for subsequent
run()calls
Maximum seconds to wait for SSH to become available.
Seconds between TCP probe attempts.
If SSH does not become available within timeout seconds.
close
Usage Patterns
Basic Command Execution
Error Handling
Using with SmolVM
Persistent Connection Benefits
Shell Modes
Performance
The persistent SSH connection provides significant performance benefits:- First command: ~100-200ms (establishes connection)
- Subsequent commands: ~10-50ms (reuses connection)
- Without persistence: ~170ms per command (fork + handshake overhead)
Related
- CommandResult - Result object returned by
run() - SmolVM - High-level VM facade that uses SSHClient internally
