Skip to main content
Deno Deploy provides Linux microVMs for isolated code execution. Best for Deno and JavaScript workloads.

Setup

npm install @langchain/deno

Authentication

Get your token from app.deno.com → Settings → Organization Tokens.
export DENO_DEPLOY_TOKEN=your_token
Or pass credentials directly:
const sandbox = await DenoSandbox.create({
  auth: { token: "your-token-here" },
});

Usage with deepagents

import { createDeepAgent } from "deepagents";
import { ChatAnthropic } from "@langchain/anthropic";
import { DenoSandbox } from "@langchain/deno";

const sandbox = await DenoSandbox.create({
  memoryMb: 1024,
  lifetime: "10m",
});

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 Deno app and run it" }],
  });
} finally {
  await sandbox.close();
}

Standalone usage

import { DenoSandbox } from "@langchain/deno";

const sandbox = await DenoSandbox.create({
  memoryMb: 1024,
  lifetime: "10m",
});

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

await sandbox.close();

Configuration

OptionTypeDefaultDescription
memoryMbnumber768Memory in MB (768-4096)
lifetime"session" | string"session"Lifetime ("session", "5m", "30s")
regionstring-Region. Options: "ams" | "ord"

Available regions

Region CodeLocation
amsAmsterdam
ordChicago

Lifetime options

  • "session" (default): Sandbox shuts down when you close/dispose the client
  • Duration string: Keep sandbox alive for a specific time (e.g., "5m", "30s")

Accessing the Deno SDK

For advanced features, access the underlying Deno SDK:
const denoSandbox = await DenoSandbox.create();
const sdk = denoSandbox.sandbox;

// Expose HTTP port
const url = await sdk.exposeHttp({ port: 3000 });

// Expose SSH
const ssh = await sdk.exposeSsh();

// Evaluate JavaScript
const result = await sdk.eval("1 + 2");

// Set environment variables
await sdk.env.set("API_KEY", "secret");

// Shell template literals
const output = await sdk.sh`echo "Hello from Deno!"`.text();

// Start a JavaScript runtime
const runtime = await sdk.createJsRuntime({ entrypoint: "server.ts" });

Reconnecting to existing sandboxes

Reconnecting requires a duration-based lifetime (not "session"):
// Create with duration lifetime
const sandbox = await DenoSandbox.create({
  memoryMb: 1024,
  lifetime: "30m",
});
const sandboxId = sandbox.id;
await sandbox.close(); // Close connection, sandbox keeps running

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

Factory functions

import { createDenoSandboxFactory, createDenoSandboxFactoryFromSandbox } from "@langchain/deno";

// Create new sandbox per invocation
const factory = createDenoSandboxFactory({ memoryMb: 1024 });

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

Error handling

import { DenoSandboxError } from "@langchain/deno";

try {
  await sandbox.execute("some command");
} catch (error) {
  if (error instanceof DenoSandboxError) {
    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 Deno Deploy token");
        break;
    }
  }
}

Error codes

CodeDescription
NOT_INITIALIZEDSandbox not initialized - call initialize()
ALREADY_INITIALIZEDCannot initialize twice
AUTHENTICATION_FAILEDInvalid or missing Deno Deploy token
SANDBOX_CREATION_FAILEDFailed to create sandbox
SANDBOX_NOT_FOUNDSandbox ID not found or expired
COMMAND_TIMEOUTCommand execution timed out
COMMAND_FAILEDCommand execution failed
FILE_OPERATION_FAILEDFile read/write failed
RESOURCE_LIMIT_EXCEEDEDCPU, memory, or storage limits exceeded

Limits and constraints

ConstraintValue
Minimum memory768 MB
Maximum memory4096 MB (4 GB)
Disk space10 GB
vCPUs2
Working directory/home/app
Network accessFull (by default)

Environment variables

VariableDescription
DENO_DEPLOY_TOKENDeno Deploy organization access token

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