Skip to content

TypeScript SDK Reference

View as Markdown

The Daytona TypeScript SDK provides a powerful interface for programmatically interacting with Daytona Sandboxes.

Install the Daytona TypeScript SDK using npm:

Terminal window
npm install @daytona/sdk

Or using yarn:

Terminal window
yarn add @daytona/sdk

Create a Daytona Sandbox to run your code securely in an isolated environment. The following snippet is an example “Hello World” program that runs securely inside a Daytona Sandbox.

import { Daytona } from '@daytona/sdk'
async function main() {
// Initialize the SDK (uses environment variables by default)
const daytona = new Daytona()
// Create a new sandbox
const sandbox = await daytona.create({
language: 'typescript',
envVars: { NODE_ENV: 'development' },
})
// Execute a command
const response = await sandbox.process.executeCommand('echo "Hello, World!"')
console.log(response.result)
}
main().catch(console.error)

The Daytona SDK can be configured using environment variables or by passing options to the constructor:

import { Daytona } from '@daytona/sdk';
// Using environment variables (DAYTONA_API_KEY, DAYTONA_API_URL, DAYTONA_TARGET)
const daytona = new Daytona();
// Using explicit configuration
const daytona = new Daytona({
apiKey: 'YOUR_API_KEY',
apiUrl: 'https://app.daytona.io/api',
target: 'us'
});

For more information on configuring the Daytona SDK, see configuration.

The TypeScript SDK ships as a dual ESM/CJS package and works out of the box in Node.js, Bun, Next.js, Nuxt.js, Remix, Vite SSR, AWS Lambda, and Azure Functions without any extra configuration.

For Cloudflare Workers, set the Node.js compatibility flag in your wrangler.toml:

compatibility_flags = ["nodejs_compat"]

For Deno, install with deno add npm:@daytona/sdk or import directly with the npm: specifier:

import { Daytona, Image } from 'npm:@daytona/sdk'

For browser apps with Vite (or any browser bundler), install vite-plugin-node-polyfills and add it to your vite.config.ts:

import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
export default defineConfig({
plugins: [nodePolyfills({ globals: { Buffer: true, process: true, global: true } })],
})

The SDK uses Node’s Buffer for binary data (downloaded files, multipart bodies). Browsers don’t ship Buffer, so the polyfill provides it. Without it, basic operations like Image.base() and daytona.list() still work, but methods that handle binary payloads (fs.downloadFile, fs.downloadFiles) will throw.

Some runtimes don’t expose the full set of Node.js APIs (browsers and edge runtimes have no filesystem, no crypto, etc.). Methods that depend on those APIs throw a clear runtime error instead of silently producing wrong results.