Skip to main content
Daytona provides fast-starting sandbox environments with multi-language support. Best for TypeScript and Python development.

Setup

npm install @langchain/daytona

Authentication

Get your API key from app.daytona.io.
export DAYTONA_API_KEY=your_api_key
Or pass credentials directly:
const sandbox = await DaytonaSandbox.create({
  auth: { apiKey: "your-api-key-here" },
});

Usage with deepagents

import { createDeepAgent } from "deepagents";
import { ChatAnthropic } from "@langchain/anthropic";
import { DaytonaSandbox } from "@langchain/daytona";

const sandbox = await DaytonaSandbox.create({
  language: "typescript",
  timeout: 300,
});

try {
  const agent = createDeepAgent({
    model: new ChatAnthropic({ model: "claude-sonnet-4-20250514" }),
    systemPrompt: "You are a coding assistant with sandbox access.",
    backend: sandbox,
  });

  const result = await agent.invoke({
    messages: [{ role: "user", content: "Create a hello world TypeScript app and run it" }],
  });
} finally {
  await sandbox.close();
}

Standalone usage

import { DaytonaSandbox } from "@langchain/daytona";

const sandbox = await DaytonaSandbox.create({
  language: "typescript",
  timeout: 300,
});

const result = await sandbox.execute("npm --version");
console.log(result.output);

await sandbox.close();

Configuration

OptionTypeDefaultDescription
languagestring"typescript"Primary language runtime. Options: "typescript" | "python" | "javascript"
timeoutnumber300Command timeout in seconds
targetstring"us"Region. Options: "us" | "eu"
imagestring-Custom Docker image (e.g., "node:20", "python:3.12")
snapshotstring-Snapshot name (cannot be used with image)
resourcesobject-CPU, memory, disk allocation (requires image)
autoStopIntervalnumber15Auto-stop after N minutes idle (0 to disable)
labelsRecord<string, string>-Custom labels for organizing sandboxes
initialFilesRecord<string, string>-Files to create on startup

Custom resources

To customize CPU, memory, or disk, you must specify a Docker image:
const sandbox = await DaytonaSandbox.create({
  image: "node:20",
  language: "typescript",
  resources: {
    cpu: 4,       // Number of CPUs
    memory: 8,    // GiB
    disk: 50,     // GiB
  },
});

Available regions

RegionLocation
usUnited States
euEurope

Accessing the Daytona SDK

For advanced features, access the underlying Daytona SDK:
const daytonaSandbox = await DaytonaSandbox.create();
const sdk = daytonaSandbox.sandbox;

// Use any Daytona SDK feature directly
const workDir = await sdk.getWorkDir();
const homeDir = await sdk.getUserHomeDir();
await sdk.fs.createFolder("src", "755");

Reconnecting to existing sandboxes

// Create sandbox with auto-stop interval
const sandbox = await DaytonaSandbox.create({
  language: "typescript",
  autoStopInterval: 60,
});
const sandboxId = sandbox.id;

// Stop the sandbox (keeps it available)
await sandbox.stop();

// Later: reconnect
const reconnected = await DaytonaSandbox.connect(sandboxId);
await reconnected.start();
const result = await reconnected.execute("ls -la");

Sandbox lifecycle

const sandbox = await DaytonaSandbox.create();

await sandbox.stop();   // Stop (can be restarted)
await sandbox.start();  // Start a stopped sandbox
await sandbox.close();  // Delete permanently

Factory functions

import { createDaytonaSandboxFactory, createDaytonaSandboxFactoryFromSandbox } from "@langchain/daytona";

// Create new sandbox per invocation
const factory = createDaytonaSandboxFactory({ language: "typescript" });

// Or reuse an existing sandbox across invocations
const sandbox = await DaytonaSandbox.create();
const reuseFactory = createDaytonaSandboxFactoryFromSandbox(sandbox);

Error handling

import { DaytonaSandboxError } from "@langchain/daytona";

try {
  await sandbox.execute("some command");
} catch (error) {
  if (error instanceof DaytonaSandboxError) {
    switch (error.code) {
      case "NOT_INITIALIZED":
        await sandbox.initialize();
        break;
      case "COMMAND_TIMEOUT":
        console.error("Command took too long");
        break;
      case "AUTHENTICATION_FAILED":
        console.error("Check your Daytona API key");
        break;
    }
  }
}

Error codes

CodeDescription
NOT_INITIALIZEDSandbox not initialized - call initialize()
ALREADY_INITIALIZEDCannot initialize twice
AUTHENTICATION_FAILEDInvalid or missing Daytona API key
SANDBOX_CREATION_FAILEDFailed to create sandbox
SANDBOX_NOT_FOUNDSandbox ID not found or deleted
SANDBOX_NOT_STARTEDSandbox is not in started state
COMMAND_TIMEOUTCommand execution timed out
COMMAND_FAILEDCommand execution failed
FILE_OPERATION_FAILEDFile read/write failed
RESOURCE_LIMIT_EXCEEDEDCPU, memory, or storage limits exceeded

Environment variables

VariableDescription
DAYTONA_API_KEYDaytona API key (required)
DAYTONA_API_URLCustom Daytona API URL
DAYTONA_TARGETDefault target region (us/eu)

Connect these docs to Claude, VSCode, and more via MCP for real-time answers.