Skip to main content
Use the Dedalus TypeScript SDK to create and manage persistent Linux machines from your application. Create one or many machines for a project, run commands, and reuse their files across sessions. Your application calls the SDK. Commands submitted through the SDK run inside the machine. You can also change machine resources, control sleep and wake, request SSH access, and inspect usage.

Install

Use TypeScript 4.9 or later and a supported runtime. The examples below use Node.js and top-level await in an ES module.

Authenticate

Create an API key in the Dedalus Dashboard, then set it in the environment:
new Dedalus() reads DEDALUS_API_KEY automatically.

Create a machine

This creates a machine with 1 vCPU, 4,096 MiB of memory, 10 GiB of storage, and autosleep after five idle minutes:
Use the saved machine.machine_id in later requests for this machine. Machine creation is asynchronous. The response contains the requested state and the machine’s current lifecycle status. You can submit an execution immediately after creation. Dedalus waits for the machine to start before running the command.

Run a command

An execution is one command run inside a machine. Creating an execution returns an execution_id before the command finishes. Use that ID to check the command’s status and retrieve its output. This example writes a file, reads it back, and waits for the execution to finish:
Example output:
Execution status is separate from API status. A successful API request can return an execution whose status is failed. Check the execution status before using its output. timeout_ms limits how long the command can run inside the machine. The execution continues independently of your application’s polling loop until it finishes, is cancelled, expires, or reaches that timeout. See Executions for working directories, environment variables, input, cancellation, and output limits.

Reuse the machine

Dedalus Machines are persistent. Save the machine ID to reuse the same filesystem across application sessions. In a later application session, you can set MACHINE_ID to the saved ID and retrieve it:
The returned savedMachine contains the machine’s current state. Submit another execution with savedMachine.machine_id to continue working. Executions wake a sleeping machine automatically. Sleep preserves files on the root filesystem and resets processes and memory. See persistence for the complete lifecycle contract. When you no longer need the machine or its files, explicitly request deletion:
Deletion removes the machine and its files. Sleep and autosleep preserve the machine for another session.

Watch lifecycle changes

watch streams machine state changes using server-sent events (SSE). desired_state is the requested state. status.phase is the machine’s current state. This example requests sleep and reads updates until the machine is sleeping:
Each update contains a complete machine response. Break from the loop or call stream.controller.abort() to close the stream. The stream closes when the machine reaches its desired state, reports a terminal error, or the five-minute watch limit expires. Retrieve the machine after the stream closes to confirm its current state:

List machines

Machine lists are paginated. limit sets the number of machines requested in each page, and cursor continues from a previous page. Use for await to fetch pages automatically:
To request one page at a time, inspect items and call getNextPage() only when you want another request:

Configure requests

Client options apply to every request. Pass request options as the second argument to a resource method to override settings for that call. This example disables retries for the client and enables two retries for one request:

Retries and timeouts

The SDK retries connection failures, HTTP 408, 409, 429, and 5xx responses twice by default, with increasing delays between attempts. An explicit x-should-retry response header overrides the status-based decision. A timed-out attempt throws APIConnectionTimeoutError and can also be retried. Because timeout applies to each attempt, a call with retries can take longer than that value.

SDK methods

The SDK groups related methods under resources. All methods accept a parameter object. Methods that act on an existing machine require machine_id. Use the API reference for every request field and response field.

Handle errors

An API request and a command can fail independently. A successful HTTP response to executions.retrieve can describe a failed command: check execution.status, exit_code, error_message, and captured stderr before using its results. After an HTTP timeout, use the execution ID to retrieve the existing execution. Submitting another command creates another execution. The client timeout controls HTTP waiting, execution timeout_ms controls command runtime, and machine autosleep controls idle compute. Failed HTTP requests throw a subclass of Dedalus.APIError. Inspect status, headers, and error for the HTTP status, response headers, and error body. Connection failures have no HTTP response. Catch errors where your application can report or handle them. This example reports diagnostic fields and rethrows the error:
The error body can include error_code, message, and retryable. Other unsuccessful status codes use the base APIError type.

Advanced client options

Work with types

The SDK exports types for request parameters and response fields. Editor autocomplete and hover documentation explain each field. Method calls infer response types, and you can add explicit annotations where they help your application.
These types provide compile-time checks and editor documentation for the API.

Inspect HTTP responses

Use .withResponse() to receive both the parsed result and the underlying Fetch Response. It resolves after the body has been read and parsed.
Example output for a successful retrieval:
Use .asResponse() to parse or stream the body yourself. It resolves when successful response headers arrive and leaves the body unread. Access headers through response.headers.get(name). This example reads the raw response body as it arrives:

Logging

Set DEDALUS_LOG or the client option logLevel. The client option takes precedence over the environment variable. The default logger is globalThis.console. Pass a compatible logger through the logger client option to send messages elsewhere. logLevel still filters messages before they reach that logger. Report logger incompatibilities in the SDK issue tracker.

Customize HTTP requests

The SDK uses the runtime’s global fetch. Replace it globally or pass a compatible implementation through the client option fetch. Set fetchOptions to customize request options while keeping the current transport. Request-level fetchOptions override client-level options. Proxy configuration depends on the runtime:

Requests beyond the generated types

client.get, client.post, and the other HTTP methods let you call endpoints that do not yet have resource methods. They retain client settings such as authentication and retries. Use the query, body, and headers request options for additional arguments. Extra fields placed directly in resource parameters go into the query for GET requests and the body for other methods. For a field absent from the generated types, a targeted @ts-expect-error can bypass the type error. A type assertion can also describe an extra response property.

Supported runtimes

The SDK supports TypeScript 4.9 or later and the following runtimes:
  • Node.js 20 or later while the release is supported.
  • Current Chrome, Firefox, Safari, and Edge browsers.
  • Deno 1.28.0 or later and Bun 1.0 or later.
  • Cloudflare Workers and Vercel Edge Runtime.
  • Jest 28 or later with the node environment.
  • Nitro 2.6 or later.

Versioning

Review the release notes before upgrading. If you depend on an internal interface, or find a compatibility issue, report it in the SDK issue tracker.
Last modified on September 9, 2026