@luxorai/sandbox
Version:
TypeScript SDK for Luxor Sandbox: cloud sandboxes (microVMs) for AI agents on Luxor Agent Cloud
171 lines (170 loc) • 11.1 kB
TypeScript
import type { CIRunnerSizes } from "./ci-runner-sizes.js";
import type { SessionCost, SessionCostBatch } from "./cost.js";
import { type EgressPolicy, type EgressPolicySpec } from "./egress-policies.js";
import { InjectionCredentialInput, type InjectionCredentialMetadata } from "./injection-credentials.js";
import type { SessionMetrics } from "./metrics.js";
import type { ClientOptions, CreateOptions, CreateSnapshotOptions, CreateTemplateOptions, CreateVolumeOptions, ListOptions, RegistryListOptions, RegistryLookupOptions, RegistryPublishOptions, RegistryShareOptions, UpdateSessionOptions, UpdateSnapshotOptions, UpdateTemplateOptions, UpdateVolumeOptions, WorkspaceScopeOptions } from "./options.js";
import { PreviewUrlClient } from "./preview-url.js";
import type { RegistryDeleteResult, RegistryImage, RegistryImageDetail, RegistryListResult, RegistryPublishResult, RegistryShareGrant, RegistryShareResult, RegistryUnshareResult, RegistryVersionDeleteResult, ResolvedRegistryRef } from "./registry.js";
import { Session } from "./session.js";
import type { Snapshot, SnapshotDownloadURL } from "./snapshot.js";
import type { SSHCert } from "./ssh-cert.js";
import type { SSHConnection } from "./ssh.js";
import type { StorageAccess, StorageAuthMethod, StorageConnection, StorageConnectionCredentials, StorageConnectionList, StorageConnectionTest, StorageDefaults, StorageProvider } from "./storage.js";
import type { Template, TemplateBuild, TemplateBuildOptions, TemplateBuildWaitOptions } from "./template.js";
import type { WorkspaceUsageLimit } from "./usage.js";
import type { Volume } from "./volume.js";
import type { Identity } from "./whoami.js";
declare const inspectCustom: unique symbol;
/** @deprecated Use {@link LuxorSandbox}; `TenkiSandbox` remains a supported alias of the same class. */
export declare class TenkiSandbox implements AsyncDisposable {
#private;
private rpcClient;
private sshGatewayClient;
private readonly baseUrl;
private gatewayAddress;
private sshOptions?;
private dataPlaneReadyTimeoutMs;
private readonly warningHandler?;
private sessionManager?;
readonly previewUrls: PreviewUrlClient;
constructor(options?: ClientOptions);
toJSON(): {
baseUrl: string;
authToken: string;
};
[inspectCustom](): string;
private verifyTailnetExposure;
private verifyPublicEgress;
private verifyTailnetDNS;
/**
* cpuCores is 1-128 and memoryMb 256-524288 MiB (even); the workspace's size limit may be lower.
* pauseRetentionMs must be at most the workspace's pause retention limit, which applies when it is unset or
* not positive; a larger value is rejected.
*/
create(options?: CreateOptions): Promise<Session>;
createWithInjectionCredentials(credentials: InjectionCredentialInput[], options?: CreateOptions): Promise<{
session: Session;
credentials: InjectionCredentialMetadata[];
}>;
private createSession;
/** @deprecated Use {@link create}, which already waits for the session to be ready. */
createAndWait(options?: CreateOptions & {
timeoutMs?: number;
}): Promise<Session>;
get(sessionId: string): Promise<Session>;
getSessionMetrics(sessionId: string, windowMs?: number): Promise<SessionMetrics>;
getSessionCost(sessionId: string): Promise<SessionCost>;
/** Returns the costs of up to 100 sessions in `options.workspaceId`, or in the API key's workspace when omitted. */
batchGetSessionCosts(sessionIds: string[], options?: WorkspaceScopeOptions): Promise<SessionCostBatch>;
list(options?: ListOptions): Promise<Session[]>;
/**
* Current usage vs. limits for a workspace — concurrent sessions, snapshots,
* volumes, etc. Each entry carries `current` and an optional `max`. Look up
* the `"max_concurrent_jobs"` key to check the shared concurrency quota before
* creating a session, so the UI can surface a "limit reached" state up front
* instead of letting the create fail.
*/
getUsage(): Promise<WorkspaceUsageLimit[]>;
updateSession(sessionId: string, options: UpdateSessionOptions): Promise<Session>;
createSnapshot(sessionId: string, options?: CreateSnapshotOptions): Promise<Snapshot>;
createSnapshotAsync(sessionId: string, options?: CreateSnapshotOptions): Promise<Snapshot>;
createSnapshotAndWait(sessionId: string, options?: CreateSnapshotOptions & {
timeoutMs?: number;
}): Promise<Snapshot>;
getSnapshot(snapshotId: string): Promise<Snapshot>;
getSnapshotDownloadURL(snapshotId: string): Promise<SnapshotDownloadURL>;
listSnapshots(options?: WorkspaceScopeOptions): Promise<Snapshot[]>;
listSessionSnapshots(sessionId: string): Promise<Snapshot[]>;
listDanglingSnapshots(): Promise<Snapshot[]>;
deleteSnapshot(snapshotId: string): Promise<Snapshot>;
updateSnapshot(snapshotId: string, options: UpdateSnapshotOptions): Promise<Snapshot>;
waitSnapshotReady(snapshotId: string, timeoutMs?: number, signal?: AbortSignal): Promise<Snapshot>;
/** Credentials go to Luxor Secrets (s3_storage scope); the connection keeps only their names. */
createStorageConnection(options: {
/** Defaults to the workspace of a workspace API key. */
workspaceId?: string;
name: string;
provider: StorageProvider;
/** May be empty for AWS_S3 (derived from region) and GCS. */
endpoint?: string;
bucket: string;
region?: string;
authMethod: StorageAuthMethod;
defaultAccess: StorageAccess;
credentials: StorageConnectionCredentials;
}): Promise<StorageConnection>;
/** Lists the connections of `workspaceId`, or of the API key's workspace when omitted. */
listStorageConnections(workspaceId?: string): Promise<StorageConnectionList>;
updateStorageConnection(connectionId: string, options: {
expectedRevision: bigint;
name?: string;
endpoint?: string;
region?: string;
defaultAccess?: StorageAccess;
credentials?: StorageConnectionCredentials;
}): Promise<StorageConnection>;
deleteStorageConnection(connectionId: string, expectedRevision: bigint): Promise<void>;
testStorageConnection(connectionId: string): Promise<StorageConnectionTest>;
getStorageDefaults(workspaceId?: string): Promise<StorageDefaults>;
/** Replaces the workspace's default mounts; pass the revision you read (0 before the first save). */
saveStorageDefaults(defaults: StorageDefaults, expectedRevision: number): Promise<StorageDefaults>;
/** Saves spec under name in the workspace; the server checks it like an inline session policy. */
createEgressPolicy(name: string, spec: EgressPolicySpec, options?: WorkspaceScopeOptions): Promise<EgressPolicy>;
/** Replaces the policy body when expectedRevision is current; existing sessions keep the policy they were created with. */
updateEgressPolicy(nameOrId: string, expectedRevision: number, spec: EgressPolicySpec, options?: WorkspaceScopeOptions): Promise<EgressPolicy>;
getEgressPolicy(nameOrId: string, options?: WorkspaceScopeOptions): Promise<EgressPolicy>;
/** Returns every live policy in the workspace, ordered by name. */
listEgressPolicies(options?: WorkspaceScopeOptions): Promise<EgressPolicy[]>;
/** Soft-deletes the policy when expectedRevision is current; sessions that pinned it keep their merged policy. */
deleteEgressPolicy(nameOrId: string, expectedRevision: number, options?: WorkspaceScopeOptions): Promise<EgressPolicy>;
createVolume(options: CreateVolumeOptions): Promise<Volume>;
getVolume(volumeId: string): Promise<Volume>;
listVolumes(options?: WorkspaceScopeOptions): Promise<Volume[]>;
deleteVolume(volumeId: string, signal?: AbortSignal): Promise<void>;
resizeVolume(volumeId: string, newSizeBytes: number): Promise<Volume>;
updateVolume(volumeId: string, options: UpdateVolumeOptions): Promise<Volume>;
waitVolumeReady(volumeId: string, timeoutMs?: number, signal?: AbortSignal): Promise<Volume>;
listRegistryImages(options?: RegistryListOptions): Promise<RegistryListResult>;
getRegistryImage(imageOrId: string, options?: RegistryLookupOptions): Promise<RegistryImageDetail>;
resolveRegistryRef(image: string, options?: RegistryLookupOptions): Promise<ResolvedRegistryRef>;
publishRegistryImage(options: RegistryPublishOptions): Promise<RegistryPublishResult>;
unpublishRegistryImage(imageOrId: string): Promise<RegistryImage>;
deleteRegistryImage(imageOrId: string, reason?: string): Promise<RegistryDeleteResult>;
deleteRegistryImageVersion(imageId: string, snapshotId: string): Promise<RegistryVersionDeleteResult>;
shareImage(imageOrId: string, options: RegistryShareOptions): Promise<RegistryShareResult>;
revokeRegistryShareGrant(grantId: string, reason?: string): Promise<RegistryShareGrant | undefined>;
listRegistryShareGrants(imageOrId: string): Promise<RegistryShareGrant[]>;
unshareRegistryImage(imageOrId: string, reason?: string): Promise<RegistryUnshareResult>;
createTemplate(options: CreateTemplateOptions): Promise<Template>;
getTemplate(template: Template | string): Promise<Template>;
listTemplates(options?: ListOptions): Promise<Template[]>;
updateTemplate(template: Template | string, options: UpdateTemplateOptions): Promise<Template>;
deleteTemplate(template: Template | string): Promise<Template>;
buildTemplate(template: Template | string, options?: TemplateBuildOptions): Promise<TemplateBuild>;
getTemplateBuild(build: TemplateBuild | string): Promise<TemplateBuild>;
listActiveTemplateBuilds(template: Template | string): Promise<TemplateBuild[]>;
/** Waits for or reconnects to a build; handler/signal failure stops local observation only. */
waitForTemplateBuild(build: TemplateBuild | string, signalOrOptions?: AbortSignal | TemplateBuildWaitOptions): Promise<TemplateBuild>;
/** Explicitly cancels the remote build; disconnecting an observer never does. */
cancelTemplateBuild(build: TemplateBuild | string): Promise<TemplateBuild>;
whoAmI(): Promise<Identity>;
/** Luxor CI runner sizes for the API key's workspace, within its job-size limits, smallest first. */
listCIRunnerSizes(): Promise<CIRunnerSizes>;
ssh(sessionId: string): Promise<SSHConnection>;
/**
* Mint a short-lived OpenSSH user certificate for the session. Authenticate
* an SSH implementation over the raw `ssh()` transport with the matching
* private key and returned certificate. OpenSSH auto-loads `sshCert` when it
* is saved beside the private key as `<key>-cert.pub`.
*/
issueSandboxSSHCert(sessionId: string, publicKey: string, options?: {
ttlMs?: number;
}): Promise<SSHCert>;
close(): void;
[Symbol.asyncDispose](): Promise<void>;
}
/** Luxor Sandbox client; the same class as {@link TenkiSandbox}. */
export declare const LuxorSandbox: typeof TenkiSandbox;
export type LuxorSandbox = TenkiSandbox;
export {};