TypeScript SDK Reference
The Daytona TypeScript SDK provides a powerful interface for programmatically interacting with Daytona Sandboxes.
Installation
Install the Daytona TypeScript SDK using npm:
npm install @daytonaio/sdk
Or using yarn:
yarn add @daytonaio/sdk
Getting Started
Here’s a simple example to help you get started with the Daytona TypeScript SDK:
import { Daytona } from '@daytonaio/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)
Configuration
The SDK can be configured using environment variables or by passing options to the constructor:
import { Daytona } from '@daytonaio/sdk';
// Using environment variables (DAYTONA_API_KEY, DAYTONA_API_URL, DAYTONA_TARGET)const daytona = new Daytona();
// Using explicit configurationconst daytona = new Daytona({ apiKey: 'your-api-key', apiUrl: 'https://app.daytona.io/api', target: 'us'});
Multiple Runtime Support
The Daytona TypeScript SDK works across multiple JavaScript runtimes including Node.js, Deno, Bun, browsers, and serverless platforms (Cloudflare Workers, AWS Lambda, Azure Functions, etc.).
Daytona in Vite Projects
When using Daytona SDK in a Vite-based project, you need to configure node polyfills to ensure compatibility. Add the following configuration to your vite.config.ts
file in the plugins array:
import { nodePolyfills } from 'vite-plugin-node-polyfills'
export default defineConfig({ plugins: [ // ... other plugins nodePolyfills({ globals: { global: true, process: true, Buffer: true }, overrides: { path: 'path-browserify-win32', }, }), ], // ... rest of your config})
Daytona in Next.js Projects
When using Daytona SDK in a Next.js project, you need to configure node polyfills to ensure compatibility with Webpack and Turbopack bundlers (depending on what you’re using). Add the following configuration to your next.config.ts
file:
import type { NextConfig } from 'next'import NodePolyfillPlugin from 'node-polyfill-webpack-plugin'import { env, nodeless } from 'unenv'
const { alias: turbopackAlias } = env(nodeless, {})
const nextConfig: NextConfig = { // Turbopack experimental: { turbo: { resolveAlias: { ...turbopackAlias, }, }, }, // Webpack webpack: (config, { isServer }) => { if (!isServer) { config.plugins.push(new NodePolyfillPlugin()) } return config },}
export default nextConfig