The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.
/* Copyright 2026 BoxLite AI. SPDX-License-Identifier: AGPL-3.0 */
import type { ApiClient } from '@/api/apiClient'
export type SshStatus = {
enabled: boolean
generation: number
listen_address: string
host_public_key: string
host_key_fingerprint: string
}
export async function requestSsh(
api: ApiClient,
organizationId: string,
boxId: string,
operation: 'status' | 'enable' | 'disable',
): Promise<SshStatus> {
const path = `v1/${encodeURIComponent(organizationId)}/boxes/${encodeURIComponent(boxId)}/ssh`
const http = api.axiosInstance
const options = { timeout: 30_000 }
const response =
operation === 'status'
? await http.get<SshStatus>(path, options)
: operation === 'disable'
? await http.delete<SshStatus>(path, options)
: await http.post<SshStatus>(`${path}/enable`, undefined, options)
const status = response.data
if (
!status ||
typeof status.enabled !== 'boolean' ||
!Number.isInteger(status.generation) ||
status.generation < 0 ||
!['listen_address', 'host_public_key', 'host_key_fingerprint'].every(
(field) => typeof status[field as keyof SshStatus] === 'string',
)
) {
throw new Error('Invalid SSH status response')
}
return status
}
export type SshInstructions = {
login: string
connect: string
}
/**
* Keep the hosted guide short: CLI defaults already target the hosted API, and
* login caches the organization. Existing CLI setups and other endpoints use the docs.
*/
export function sshConnectionInstructions(boxId: string): SshInstructions {
if (!/^[A-Za-z0-9_][A-Za-z0-9_-]*$/.test(boxId)) throw new Error('Invalid box ID')
return {
connect: `boxlite ssh ${boxId}`,
login: 'boxlite auth login',
}
}