Promise-based TypeScript client for sessh - manage persistent SSH sessions from TypeScript/JavaScript.
npm install
npm run buildOr as a dependency:
npm install git+https://github.com/CommandAGI/sessh-typescript-sdk.git- Node.js 18+
- The
sesshCLI must be installed and on your PATH
import { SesshClient } from "sessh-sdk";
// Create a client
const client = new SesshClient({
alias: "agent",
host: "ubuntu@203.0.113.10",
identity: "~/.ssh/id_ed25519"
});
// Open a session
await client.open();
// Run commands
await client.run("python train.py");
// Get logs
const logs = await client.logs(400);
console.log(logs.output);
// Check status
const status = await client.status();
console.log(`Master: ${status.master}, Session: ${status.session}`);
// Close session
await client.close();Initialize a sessh client.
Options:
alias(string): Session alias namehost(string): SSH host (user@host)port(number, optional): SSH port (default: 22)sesshBin(string, optional): Path to sessh binary (default: "sessh" from PATH)identity(string, optional): Path to SSH private keyproxyjump(string, optional): ProxyJump host (e.g., "bastionuser@bastion")
Open or ensure a persistent remote tmux session.
Send a command into the persistent tmux session.
Capture recent output from the tmux session.
Check whether the SSH controlmaster and tmux session exist.
Kill tmux session and close the controlmaster.
Send individual key events to the tmux session (no Enter key). Useful for interactive TUI programs like vim or nano.
Read the current pane state from the tmux session. Useful for reading the current state of interactive TUI programs.
interface SesshResponse {
ok: boolean;
op: string;
[key: string]: unknown;
}
interface LogsResponse extends SesshResponse {
output?: string;
lines?: number;
}
interface StatusResponse extends SesshResponse {
master: number;
session: number;
}# Install dependencies
npm install
# Build
npm run build
# Run tests
npm testComprehensive examples are available in the examples/ directory. Each example demonstrates launching infrastructure, using sessh to manage persistent sessions, and cleaning up resources.
import { SesshClient } from "sessh-sdk";
const client = new SesshClient({
alias: "local-test",
host: "user@localhost"
});
await client.open();
await client.run("echo 'Hello from sessh!'");
const logs = await client.logs(50);
console.log(logs.output);
await client.close();import { SesshClient } from "sessh-sdk";
// Launch EC2 instance, get IP (example)
const ip = "203.0.113.10";
const client = new SesshClient({
alias: "aws-agent",
host: `ubuntu@${ip}`
});
await client.open();
await client.run("python train.py");
const logs = await client.logs(400);
await client.close();import { SesshClient } from "sessh-sdk";
// Launch Lambda Labs instance, get IP (example)
const ip = "203.0.113.10";
const client = new SesshClient({
alias: "lambda-agent",
host: `ubuntu@${ip}`,
identity: "~/.ssh/id_ed25519"
});
await client.open();
await client.run("pip install torch torchvision");
await client.run("python train.py");
const logs = await client.logs(400);
console.log(logs.output);
await client.close();import { SesshClient } from "sessh-sdk";
const client = new SesshClient({
alias: "editor",
host: "ubuntu@host"
});
await client.open();
// Launch vim
await client.run("vim file.txt");
// Read current pane to see vim's state
const pane = await client.pane(30);
console.log(pane.output);
// Send key sequences to navigate and edit
await client.keys("i"); // Enter insert mode
await client.keys("Hello"); // Type text
await client.keys("Esc"); // Exit insert mode
await client.keys(":wq"); // Save and quit
await client.keys("Enter"); // Confirm
// Read pane again to verify
const pane2 = await client.pane(30);
console.log(pane2.output);
await client.close();All examples follow the same pattern:
- Launch infrastructure (instance/container)
- Wait for SSH to be ready
- Open sessh session
- Run commands (state persists between commands)
- Fetch logs
- Clean up resources
Example Files:
examples/local.ts- Localhost/local VMexamples/docker.ts- Docker containerexamples/aws.ts- AWS EC2examples/gcp.ts- Google Cloud Platformexamples/lambdalabs.ts- Lambda Labs GPUexamples/azure.ts- Microsoft Azureexamples/digitalocean.ts- DigitalOceanexamples/docker-compose.ts- Docker Compose
Running Examples:
# Build first
npm run build
# Local example
node dist/examples/local.js localhost
# AWS example (requires AWS credentials)
export AWS_REGION=us-east-1
export AWS_KEY_NAME=my-key
node dist/examples/aws.js
# Lambda Labs example (requires API key)
export LAMBDA_API_KEY=sk_live_...
export LAMBDA_SSH_KEY=my-ssh-key
node dist/examples/lambdalabs.jsIntegration tests are available in tests/examples.test.ts. These tests require real infrastructure and are skipped by default.
Running Integration Tests:
# Enable integration tests
export SESSH_INTEGRATION_TESTS=1
# For local tests
export SESSH_TEST_HOST=localhost
npm test -- tests/examples.test.tsimport { SesshClient } from "sessh-sdk";
const client = new SesshClient({
alias: "test",
host: "ubuntu@host"
});
try {
await client.open();
await client.run("some-command");
} catch (error) {
console.error("Error:", error);
process.exit(1);
} finally {
await client.close();
}"sessh: command not found"
- Ensure
sesshCLI is installed and on PATH - Or set
sesshBinoption:new SesshClient({ ..., sesshBin: "/usr/local/bin/sessh" })
Error on operations
- Check that
sesshCLI works from command line - Verify SSH key permissions and configuration
- Ensure remote host has tmux installed
JSON parsing errors
- The SDK automatically sets
SESSH_JSON=1 - Verify
sesshCLI supports JSON output
See CONTRIBUTING.md for development guidelines.
- sessh - Core CLI
- sessh-mcp - MCP server for Cursor
- sessh-python-sdk - Python SDK
MIT License - see LICENSE file for details.