UNPKG

@luxorai/sandbox

Version:

TypeScript SDK for Luxor Sandbox: cloud sandboxes (microVMs) for AI agents on Luxor Agent Cloud

153 lines (152 loc) • 6.91 kB
import { type JsonValue } from "@bufbuild/protobuf"; import type { TemplateBuildSpec as ProtoTemplateBuildSpec, TemplateRuntime as ProtoTemplateRuntime } from "./internal/proto/tenki/sandbox/v1/template_pb.js"; import { type RuntimeSecretFile } from "./secret-files.js"; export declare const TEMPLATE_SPEC_VERSION = "tenki.template.v1"; /** Successor of TEMPLATE_SPEC_VERSION; accepted once enabled for the environment and defaults workdir to /home/sandbox. */ export declare const TEMPLATE_SPEC_VERSION_LUXOR = "luxor.template.v1"; export interface GitContextOptions { repo: string; /** Branch, tag, or commit SHA. */ ref: string; checkout?: { /** Absolute guest path; defaults to the template workdir. */ dest?: string; /** "contents" places repository contents in dest; "directory" under a child directory. */ mode?: "contents" | "directory"; /** Child directory name; only valid in directory mode. */ name?: string; }; ignore?: string[]; } export interface TemplateStepOptions { name?: string; } export interface TemplateRunOptions extends TemplateStepOptions { workdir?: string; timeoutSeconds?: number; } export interface TemplateWriteFileOptions extends TemplateStepOptions { mode?: number; } export interface TemplateMkdirOptions extends TemplateStepOptions { parents?: boolean; mode?: number; } export interface TemplateRemoveOptions extends TemplateStepOptions { recursive?: boolean; } export type TemplateReadyCheck = { port: number; } | { http: string | { url: string; successStatusCodes?: number[]; }; } | { exec: string | { command?: string; argv?: string[]; timeoutSeconds?: number; }; }; export interface TemplateReadyWhen { timeoutSeconds?: number; pollIntervalSeconds?: number; checks?: TemplateReadyCheck[]; } export type TemplateRunAt = "boot" | "build" | "manual"; export type TemplateRestartPolicyOption = "never" | "on-failure" | "always"; export type TemplateSnapshotModeOption = "filesystem" | "memory"; export interface TemplateRuntimeOptions { secretPolicies?: string[]; /** Environment targets mapped to secret names in the launching workspace. */ secretEnv?: Record<string, string>; secretFiles?: RuntimeSecretFile[]; runAt?: TemplateRunAt; restartPolicy?: TemplateRestartPolicyOption; snapshotMode?: TemplateSnapshotModeOption; readyWhen?: TemplateReadyCheck[] | TemplateReadyWhen; stopGraceSeconds?: number; } export interface TemplateStartOptions extends TemplateRuntimeOptions { workdir?: string; } export interface TemplateProcessComposeOptions extends TemplateRuntimeOptions { workdir?: string; /** Dotenv files loaded explicitly, workdir-relative. */ envFiles?: string[]; } export interface TemplateSpecResources { cpuCores?: number; memoryMb?: number; diskSizeGb?: number; } export interface TemplateSpecViolation { field: string; message: string; } /** Immutable fluent builder for the typed v1 template build spec; defaults to base image "sandbox". */ export declare class TemplateSpec { private proto; constructor(); /** Strictly decode authored JSON with short or protobuf enum names; unknown fields are rejected. */ static fromJSON(json: string | JsonValue): TemplateSpec; /** @internal */ static fromProto(proto: ProtoTemplateBuildSpec): TemplateSpec; /** @internal */ toProto(): ProtoTemplateBuildSpec; /** @internal Extract the managed runtime for direct Session launch. */ toDirectRuntimeProto(): ProtoTemplateRuntime; /** Authored JSON document with short enum values; `JSON.stringify(spec)` uses this. */ toJSON(): JsonValue; /** Base on a Luxor-managed image ID or qualified Luxor registry ref. */ fromImage(image: string): TemplateSpec; /** Base on a parent template. */ fromTemplate(template: string | { id: string; }): TemplateSpec; /** Base on a parent snapshot. */ fromSnapshot(snapshot: string | { id: string; }): TemplateSpec; /** Backend-fetched Git build context; the .git directory is retained unless ignored. */ withGitContext(context: GitContextOptions): TemplateSpec; /** Default directory for Git checkout, build commands, and runtime processes. */ workdir(path: string): TemplateSpec; /** Persisted non-secret build environment, merged into any previous values. */ buildEnv(env: Record<string, string>): TemplateSpec; /** Shell-form build command (sh -lc). */ run(command: string, options?: TemplateRunOptions): TemplateSpec; /** Argv-form build command executed directly, without a shell. */ runArgs(argv: string[], options?: TemplateRunOptions): TemplateSpec; /** Copy from the materialized Git context (src is context-relative) to an absolute guest path. */ copy(src: string, dest: string, options?: TemplateStepOptions): TemplateSpec; /** Write an inline small file at an absolute guest path. */ writeFile(path: string, content: string | Uint8Array, options?: TemplateWriteFileOptions): TemplateSpec; mkdir(path: string, options?: TemplateMkdirOptions): TemplateSpec; remove(path: string, options?: TemplateRemoveOptions): TemplateSpec; rename(src: string, dest: string, options?: TemplateStepOptions): TemplateSpec; symlink(target: string, path: string, options?: TemplateStepOptions): TemplateSpec; apt(packages: string[], options?: TemplateStepOptions): TemplateSpec; pip(packages: string[], options?: TemplateStepOptions): TemplateSpec; npm(packages: string[], options?: TemplateStepOptions): TemplateSpec; bun(packages: string[], options?: TemplateStepOptions): TemplateSpec; /** Persisted process-scoped runtime environment, merged into any previous values. */ runtimeEnv(env: Record<string, string>): TemplateSpec; /** Single shell-form runtime start command. */ start(command: string, options?: TemplateStartOptions): TemplateSpec; /** Single argv-form runtime start command. */ startArgs(argv: string[], options?: TemplateStartOptions): TemplateSpec; /** Process-compose supervised runtime; configPath and envFiles are workdir-relative. */ processCompose(configPath: string, options?: TemplateProcessComposeOptions): TemplateSpec; /** Readiness contract shared by build, boot, manual start, and cold fallback. */ readyWhen(readyWhen: TemplateReadyCheck[] | TemplateReadyWhen): TemplateSpec; /** Default CPU/memory/disk for the build VM and launched sandboxes. */ resources(resources: TemplateSpecResources): TemplateSpec; /** Best-effort local field/message violations; server validation remains authoritative. */ validate(): TemplateSpecViolation[]; private update; private addStep; private addPackageStep; private setStart; }