import type { GpuType, SandboxVolume } from '@daytona/api-client'; import type { AxiosInstance } from 'axios'; import { Image } from './Image.js'; import { Sandbox } from './Sandbox.js'; import type { ListSandboxesQuery } from './Sandbox.js'; import { SecretService } from './Secret.js'; import { SnapshotService } from './Snapshot.js'; import { VolumeService } from './Volume.js'; import { WarmPoolService } from './WarmPool.js'; export declare const CODE_TOOLBOX_LANGUAGE_LABEL = "code-toolbox-language"; /** * Represents a volume mount for a Sandbox. * * @interface * @property {string} volumeId - ID or name of the Volume to mount * @property {string} mountPath - Path on the Sandbox to mount the Volume */ export interface VolumeMount extends SandboxVolume { volumeId: string; mountPath: string; } /** * Configuration options for initializing the Daytona client. * * @interface * @property {string} apiKey - API key for authentication with the Daytona API * @property {string} jwtToken - JWT token for authentication with the Daytona API. If not set, it must be provided * via the environment variable `DAYTONA_JWT_TOKEN`, or an API key must be provided instead. * @property {string} organizationId - Organization ID used for JWT-based authentication. Required if a JWT token * is provided, and must be set either here or in the environment variable `DAYTONA_ORGANIZATION_ID`. * @property {string} apiUrl - URL of the Daytona API. Defaults to 'https://app.daytona.io/api' * if not set here and not set in environment variable DAYTONA_API_URL. * @property {string} target - Target location for Sandboxes * @property {boolean} otelEnabled - OpenTelemetry tracing enabled. * If set, all SDK operations will be traced. * * @example * const config: DaytonaConfig = { * apiKey: "your-api-key", * apiUrl: "https://your-api.com", * target: "us" * }; * const daytona = new Daytona(config); */ export interface DaytonaConfig { /** API key for authentication with the Daytona API */ apiKey?: string; /** JWT token for authentication with the Daytona API */ jwtToken?: string; /** Organization ID for authentication with the Daytona API */ organizationId?: string; /** URL of the Daytona API. */ apiUrl?: string; /** * @deprecated Use `apiUrl` instead. This property will be removed in future versions. */ serverUrl?: string; /** Target environment for sandboxes */ target?: string; /** Enable OpenTelemetry tracing for SDK operations. */ otelEnabled?: boolean; /** * Observe sandbox state by legacy polling instead of WebSocket event streaming. * Defaults to `false`, where state changes are streamed over WebSocket. Can also * be enabled via the `DAYTONA_USE_DEPRECATED_POLLING` environment variable. * * @deprecated Polling-only mode will be removed in a future release. Event * streaming is the default and falls back to polling automatically when * WebSockets are unavailable. */ useDeprecatedPolling?: boolean; /** * Maximum time in milliseconds the SDK waits for a single HTTP response before * failing the request. Applies to the Daytona API client and to the toolbox * clients of every Sandbox obtained from this Daytona instance. Defaults to * 24 hours; `0` disables the deadline. * * This is a client-side deadline only — it does not cancel the operation on * the server. Calls that carry their own operation or execution timeout * (e.g. `create`, `start`, `stop`, `fork`, `process.executeCommand`, * `process.codeRun`) are not capped by this value; their HTTP wait is * bounded by that per-call timeout instead. */ requestTimeoutMs?: number; /** Configuration for experimental features */ _experimental?: Record; } /** * Supported programming languages for code execution * * Python is used as the default sandbox language when no language is explicitly specified. */ export declare enum CodeLanguage { PYTHON = "python", TYPESCRIPT = "typescript", JAVASCRIPT = "javascript" } /** * Resource allocation for a Sandbox. * * @interface * @property {number} [cpu] - CPU allocation for the Sandbox in cores * @property {number} [gpu] - GPU allocation for the Sandbox in units * @property {number} [memory] - Memory allocation for the Sandbox in GiB * @property {number} [disk] - Disk space allocation for the Sandbox in GiB * * @example * const resources: SandboxResources = { * cpu: 2, * memory: 4, // 4GiB RAM * disk: 20 // 20GiB disk * }; */ export interface Resources { /** CPU allocation for the Sandbox */ cpu?: number; /** GPU allocation for the Sandbox */ gpu?: number; /** Preferred GPU type for the Sandbox */ gpuType?: GpuType | GpuType[]; /** Memory allocation for the Sandbox in GiB */ memory?: number; /** Disk space allocation for the Sandbox in GiB */ disk?: number; } /** * Base parameters for creating a new Sandbox. * * @interface * @property {string} [user] - Optional os user to use for the Sandbox * @property {CodeLanguage | string} [language] - Programming language for direct code execution. Defaults to "python" if not specified. * @property {Record} [envVars] - Optional environment variables to set in the Sandbox * @property {Record} [labels] - Sandbox labels * @property {boolean} [public] - Is the Sandbox port preview public * @property {number} [autoStopInterval] - Auto-stop interval in minutes (0 means disabled). Default is 15 minutes (for sandbox classes that support pausing, auto-pause defaults to 60 minutes instead and auto-stop is disabled). * @property {number} [autoPauseInterval] - Auto-pause interval in minutes (0 means disabled). Only supported for sandbox classes that support pausing. Not allowed for ephemeral sandboxes. At most one of autoStopInterval and autoPauseInterval may be non-zero. For non-ephemeral sandbox classes that support pausing, defaults to 60 minutes (with auto-stop disabled) when neither interval is provided. * @property {number} [autoArchiveInterval] - Auto-archive interval in minutes (0 means the maximum interval will be used). Default is 7 days. * @property {number} [autoDeleteInterval] - Auto-delete interval in minutes (negative value means disabled, 0 means delete immediately upon stopping). By default, auto-delete is disabled. * @property {number} [ttlMinutes] - Maximum time to live in minutes, counted as wall-clock time since creation regardless of sandbox state (0 means disabled). When it elapses the Sandbox is destroyed, even if it is stopped, paused, or archived. * @property {VolumeMount[]} [volumes] - Optional array of volumes to mount to the Sandbox * @property {boolean} [networkBlockAll] - Whether to block all network access for the Sandbox * @property {string} [networkAllowList] - Comma-separated list of allowed CIDR network addresses for the Sandbox * @property {string} [domainAllowList] - Comma-separated list of allowed domains for the Sandbox * @property {string} [outboundProxyUrl] - Outbound proxy URL to route the Sandbox HTTP(S) traffic through. Applied via the HTTP(S)_PROXY environment variables (convenience routing, not a security boundary on its own); combine with domainAllowList for unbypassable network-layer enforcement. * @property {string} [otelEndpointOverride] - OTel collector endpoint override for the Sandbox. When set, sandbox OTel data is sent to this endpoint instead of the default collector and will not be available in the Daytona analytics API or dashboard. * @property {boolean} [ephemeral] - Whether the Sandbox should be ephemeral. If true, autoDeleteInterval will be set to 0. * @property {boolean} [spot] - GPU-only. When true, the Sandbox may be instantly terminated without notice to free GPU capacity for an on-demand (non-spot) GPU Sandbox. Rejected when the Sandbox requests no GPUs. * @property {string} [linkedSandbox] - ID or name of an existing sandbox to link the new sandbox to. The new sandbox will be scheduled on the same runner as the linked sandbox so a local network can be established between them. Linked sandboxes must be ephemeral (autoDeleteInterval=0) and cannot themselves be linked to another sandbox. * @property {Record} [secrets] - Optional map of environment variable name to the name of an existing organization Secret to mount into the Sandbox. The env var is set to the Secret's opaque placeholder; the real value is substituted transparently on outbound requests to the Secret's allowed hosts. Every referenced Secret name must already exist in the organization. */ export type CreateSandboxBaseParams = { name?: string; user?: string; language?: CodeLanguage | string; envVars?: Record; labels?: Record; public?: boolean; autoStopInterval?: number; autoPauseInterval?: number; autoArchiveInterval?: number; autoDeleteInterval?: number; ttlMinutes?: number; volumes?: VolumeMount[]; networkBlockAll?: boolean; networkAllowList?: string; domainAllowList?: string; outboundProxyUrl?: string; otelEndpointOverride?: string; ephemeral?: boolean; spot?: boolean; linkedSandbox?: string; secrets?: Record; }; /** * Parameters for creating a new Sandbox. * * @interface * @property {string | Image} [image] - Custom Docker image to use for the Sandbox. If an Image object is provided, * the image will be dynamically built. * @property {Resources} [resources] - Resource allocation for the Sandbox. If not provided, sandbox will * have default resources. */ export type CreateSandboxFromImageParams = CreateSandboxBaseParams & { image: string | Image; resources?: Resources; }; /** * Parameters for creating a new Sandbox from a snapshot. * * @interface * @property {string} [snapshot] - Name of the snapshot to use for the Sandbox. */ export type CreateSandboxFromSnapshotParams = CreateSandboxBaseParams & { snapshot?: string; }; /** * Parameters for forking a Sandbox. * * @property {string} [name] - Optional name for the forked Sandbox. If not provided, a unique name will be generated. */ export type ForkSandboxParams = { /** Optional name for the forked Sandbox. If not provided, a unique name will be generated. */ name?: string; }; /** * Main class for interacting with the Daytona API. * Provides methods for creating, managing, and interacting with Daytona Sandboxes. * Can be initialized either with explicit configuration or using environment variables. * * @property {VolumeService} volume - Service for managing Daytona Volumes * @property {SnapshotService} snapshot - Service for managing Daytona Snapshots * @property {SecretService} secret - Service for managing Daytona Secrets * @property {WarmPoolService} warmPool - Service for managing Daytona Warm Pools * * @example * // Using environment variables * // Uses DAYTONA_API_KEY, DAYTONA_API_URL, DAYTONA_TARGET * const daytona = new Daytona(); * const sandbox = await daytona.create(); * * @example * // Using explicit configuration * const config: DaytonaConfig = { * apiKey: "your-api-key", * apiUrl: "https://your-api.com", * target: "us" * }; * const daytona = new Daytona(config); * * @example * // Disposes daytona and flushes traces when done * await using daytona = new Daytona({ * otelEnabled: true, * }); * @class */ export declare class Daytona implements AsyncDisposable { private readonly clientConfig; private readonly sandboxApi; private readonly objectStorageApi; private readonly configApi; private analyticsApiUrlPromise?; /** * Resolves the deployment's Analytics API URL via `/config`, cached for the client's * lifetime. The in-flight promise is shared by concurrent callers; a rejected lookup * is evicted so the next call retries. */ private readonly getAnalyticsApiUrl; private readonly target?; private readonly apiKey?; private readonly jwtToken?; private readonly organizationId?; private readonly apiUrl; private readonly requestTimeoutMs?; private otelSdk?; private eventDispatcher?; private eventSubscriptionManager; readonly volume: VolumeService; readonly snapshot: SnapshotService; readonly secret: SecretService; readonly warmPool: WarmPoolService; /** * Creates a new Daytona client instance. * * @param {DaytonaConfig} [config] - Configuration options * @throws {DaytonaAuthenticationError} When no credentials are provided (neither API key nor JWT token) * @throws {DaytonaAuthenticationError} When JWT token is provided without an organization ID */ constructor(config?: DaytonaConfig); [Symbol.asyncDispose](): Promise; /** * Creates Sandboxes from specified or default snapshot. You can specify various parameters, * including language, image, environment variables, and volumes. * * @param {CreateSandboxFromSnapshotParams} [params] - Parameters for Sandbox creation from snapshot * @param {object} [options] - Options for the create operation * @param {number} [options.timeout] - Timeout in seconds (0 means no timeout, default is 60) * @returns {Promise} The created Sandbox instance * * @example * const sandbox = await daytona.create(); * * @example * // Create a custom sandbox * const params: CreateSandboxFromSnapshotParams = { * language: 'typescript', * snapshot: 'my-snapshot-id', * envVars: { * NODE_ENV: 'development', * DEBUG: 'true' * }, * autoStopInterval: 60, * autoArchiveInterval: 60, * autoDeleteInterval: 120 * }; * const sandbox = await daytona.create(params, { timeout: 100 }); */ create(params?: CreateSandboxFromSnapshotParams, options?: { timeout?: number; }): Promise; /** * Creates Sandboxes from specified image available on some registry or declarative Daytona Image. You can specify various parameters, * including resources, language, image, environment variables, and volumes. Daytona creates snapshot from * provided image and uses it to create Sandbox. * * @param {CreateSandboxFromImageParams} [params] - Parameters for Sandbox creation from image * @param {object} [options] - Options for the create operation * @param {number} [options.timeout] - Timeout in seconds (0 means no timeout, default is 60) * @param {function} [options.onSnapshotCreateLogs] - Callback function to handle snapshot creation logs. * @returns {Promise} The created Sandbox instance * * @example * const sandbox = await daytona.create({ image: 'debian:12.9' }, { timeout: 90, onSnapshotCreateLogs: console.log }); * * @example * // Create a custom sandbox * const image = Image.base('alpine:3.18').pipInstall('numpy'); * const params: CreateSandboxFromImageParams = { * language: 'typescript', * image, * envVars: { * NODE_ENV: 'development', * DEBUG: 'true' * }, * resources: { * cpu: 2, * memory: 4 // 4GB RAM * }, * autoStopInterval: 60, * autoArchiveInterval: 60, * autoDeleteInterval: 120 * }; * const sandbox = await daytona.create(params, { timeout: 100, onSnapshotCreateLogs: console.log }); */ create(params?: CreateSandboxFromImageParams, options?: { onSnapshotCreateLogs?: (chunk: string) => void; timeout?: number; }): Promise; /** * Gets a Sandbox by its ID or name. * * @param {string} sandboxIdOrName - The ID or name of the Sandbox to retrieve * @returns {Promise} The Sandbox * * @example * const sandbox = await daytona.get('my-sandbox-id-or-name'); * console.log(`Sandbox state: ${sandbox.state}`); */ get(sandboxIdOrName: string): Promise; /** * Iterates over Sandboxes matching the given query. * * @param {ListSandboxesQuery} [query] - Optional filters, sorting, and per-page size. * @returns {AsyncIterableIterator} * * @example * for await (const sandbox of daytona.list({ labels: { env: 'dev' } })) { * console.log(sandbox.id) * } */ list(query?: ListSandboxesQuery): AsyncIterableIterator; private ensureToolboxProxyUrl; /** * Starts a Sandbox and waits for it to be ready. * * @param {Sandbox} sandbox - The Sandbox to start * @param {number} [timeout] - Optional timeout in seconds (0 means no timeout) * @returns {Promise} * * @example * const sandbox = await daytona.get('my-sandbox-id'); * // Wait up to 60 seconds for the sandbox to start * await daytona.start(sandbox, 60); */ start(sandbox: Sandbox, timeout?: number): Promise; /** * Stops a Sandbox. * * @param {Sandbox} sandbox - The Sandbox to stop * @returns {Promise} * * @example * const sandbox = await daytona.get('my-sandbox-id'); * await daytona.stop(sandbox); */ stop(sandbox: Sandbox): Promise; /** * Forks a Sandbox, creating a new Sandbox with an identical filesystem. * * @param {Sandbox} sandbox - The Sandbox to fork * @param {ForkSandboxParams} [params] - Fork parameters * @param {string} [params.name] - Optional name for the forked Sandbox * @param {number} [timeout] - Timeout in seconds (0 means no timeout, default is 60) * @returns {Promise} The forked Sandbox * * @example * const sandbox = await daytona.get('my-sandbox-id'); * const forked = await daytona.fork(sandbox, { name: 'my-fork' }); * console.log(`Forked sandbox: ${forked.id}`); */ fork(sandbox: Sandbox, params?: ForkSandboxParams, timeout?: number): Promise; /** * @deprecated Use `fork` instead. This method will be removed in a future version. * @see {@link Daytona.fork} */ _experimental_fork(sandbox: Sandbox, params?: ForkSandboxParams, timeout?: number): Promise; /** * Deletes a Sandbox. * * @param {Sandbox} sandbox - The Sandbox to delete * @param {number} timeout - Timeout in seconds (0 means no timeout, default is 60) * @param {boolean} wait - If true, wait until the Sandbox is destroyed (default is false) * @returns {Promise} * * @example * const sandbox = await daytona.get('my-sandbox-id'); * await daytona.delete(sandbox); */ delete(sandbox: Sandbox, timeout?: number, wait?: boolean): Promise; /** * @hidden */ static createAxiosInstance(requestTimeoutMs?: number): AxiosInstance; } //# sourceMappingURL=Daytona.d.ts.map