> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deno

> Use Deno sandbox backends with deepagents for isolated code execution in Linux microVMs

[Deno Deploy](https://deno.com) provides Linux microVMs for isolated code execution. Best for Deno and JavaScript workloads.

## Setup

<CodeGroup>
  ```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  npm install @langchain/deno
  ```

  ```bash yarn theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  yarn add @langchain/deno
  ```

  ```bash pnpm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pnpm add @langchain/deno
  ```
</CodeGroup>

### Authentication

Get your token from [app.deno.com](https://app.deno.com) → Settings → Organization Tokens.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export DENO_DEPLOY_TOKEN=your_token
```

Or pass credentials directly:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
const sandbox = await DenoSandbox.create({
  auth: { token: "your-token-here" },
});
```

## Usage with deepagents

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
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

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
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

| Option     | Type                  | Default     | Description                             |
| ---------- | --------------------- | ----------- | --------------------------------------- |
| `memoryMb` | `number`              | `768`       | Memory in MB (768-4096)                 |
| `lifetime` | `"session" \| string` | `"session"` | Lifetime (`"session"`, `"5m"`, `"30s"`) |
| `region`   | `string`              | -           | Region. Options: `"ams" \| "ord"`       |

### Available regions

| Region Code | Location  |
| ----------- | --------- |
| `ams`       | Amsterdam |
| `ord`       | Chicago   |

### 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:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
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"`):

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
// 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

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
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

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
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

| Code                      | Description                                   |
| ------------------------- | --------------------------------------------- |
| `NOT_INITIALIZED`         | Sandbox not initialized - call `initialize()` |
| `ALREADY_INITIALIZED`     | Cannot initialize twice                       |
| `AUTHENTICATION_FAILED`   | Invalid or missing Deno Deploy token          |
| `SANDBOX_CREATION_FAILED` | Failed to create sandbox                      |
| `SANDBOX_NOT_FOUND`       | Sandbox ID not found or expired               |
| `COMMAND_TIMEOUT`         | Command execution timed out                   |
| `COMMAND_FAILED`          | Command execution failed                      |
| `FILE_OPERATION_FAILED`   | File read/write failed                        |
| `RESOURCE_LIMIT_EXCEEDED` | CPU, memory, or storage limits exceeded       |

## Limits and constraints

| Constraint        | Value             |
| ----------------- | ----------------- |
| Minimum memory    | 768 MB            |
| Maximum memory    | 4096 MB (4 GB)    |
| Disk space        | 10 GB             |
| vCPUs             | 2                 |
| Working directory | `/home/app`       |
| Network access    | Full (by default) |

## Environment variables

| Variable            | Description                           |
| ------------------- | ------------------------------------- |
| `DENO_DEPLOY_TOKEN` | Deno Deploy organization access token |

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/javascript/integrations/providers/deno.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
