LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangSmith
  • Client
  • Run Trees
  • Traceable
  • Evaluation
  • Schemas
  • Langchain
  • Jest
  • Vitest
  • Wrappers
  • Anonymizer
  • Jestlike
  • Vercel
  • Anthropic
  • Sandbox
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangSmith
ClientRun TreesTraceableEvaluationSchemasLangchainJestVitestWrappersAnonymizerJestlikeVercelAnthropicSandbox
Language
Theme
JavaScriptlangsmithsandbox
Module●Since v0.8

sandbox

LangSmith Sandbox Module.

This module provides sandboxed code execution capabilities through the LangSmith Sandbox API.

Copy
import { ... } from "langsmith/sandbox";

Example

Copy
import { SandboxClient } from "langsmith/sandbox";

// Uses LANGSMITH_ENDPOINT and LANGSMITH_API_KEY from environment
const client = new SandboxClient();

const snapshot = await client.createSnapshot(
  "python",
  "python:3.12-slim",
  1_073_741_824
);
const sandbox = await client.createSandbox(snapshot.id);
try {
  const result = await sandbox.run("python --version");
  console.log(result.stdout);
} finally {
  await sandbox.delete();
}

Functions

function
awsAuth→ SandboxAwsAuthRule

Build a sandbox proxy rule that signs AWS HTTPS requests with SigV4.

function
gcpAuth→ SandboxGcpAuthRule

Build a sandbox proxy rule that injects GCP OAuth bearer auth.

function
gcsMount→ GCSMountSpec
function
gitMount→ GitMountSpec
function
mountConfig→ SandboxMountConfig
function
opaqueSecret→ SandboxProxySecret

Provide a write-only secret value for a sandbox proxy configuration.

function
proxyConfig→ SandboxProxyConfig

Build a sandbox proxy config from one or more proxy rules.

function
s3Mount→ S3MountSpec
function
workspaceSecret→ SandboxProxySecret

Reference a LangSmith workspace secret in a sandbox proxy configuration.

Classes

class
CommandHandle

Async handle to a running command with streaming output and auto-reconnect.

Async iterable, yielding OutputChunk objects (stdout and stderr interleaved in arrival order). Access .result after iteration to get the full ExecutionResult.

Auto-reconnect behavior:

  • Server hot-reload (1001 Going Away): reconnect immediately
  • Network error / unexpected close: reconnect with exponential backoff
  • User called kill(): do NOT reconnect (propagate error)
class
LangSmithCommandTimeoutError

Raised when a command exceeds its timeout.

class
LangSmithDataplaneNotConfiguredError

Raised when dataplane_url is not available for the sandbox.

This occurs when the sandbox-router URL is not configured for the cluster.

class
LangSmithQuotaExceededError

Raised when organization quota limits are exceeded.

Users should contact technical support via our Support Portal (https://support.langchain.com) to increase quotas.

class
LangSmithResourceAlreadyExistsError

Raised when creating a resource that already exists.

class
LangSmithResourceCreationError

Raised when resource provisioning fails (general-purpose).

class
LangSmithResourceInUseError

Raised when deleting a resource that is still in use.

class
LangSmithResourceNameConflictError

Raised when updating a resource name to one that already exists.

class
LangSmithResourceNotFoundError

Raised when a resource is not found.

class
LangSmithResourceTimeoutError

Raised when an operation times out.

class
LangSmithSandboxAPIError

Raised when the API endpoint returns an unexpected error.

For example, this is raised for wrong URL or path.

class
LangSmithSandboxAuthenticationError

Raised when authentication fails (invalid or missing API key).

class
LangSmithSandboxConnectionError

Raised when connection to the sandbox server fails.

class
LangSmithSandboxCreationError

Raised when sandbox creation fails.

class
LangSmithSandboxError

Base exception for sandbox client errors.

class
LangSmithSandboxNotReadyError

Raised when attempting to interact with a sandbox that is not ready.

class
LangSmithSandboxOperationError

Raised when a sandbox operation fails (run, read, write).

class
LangSmithSandboxServerReloadError

Raised when the sandbox server is reloading (close code 1001).

Subclass of connection error that signals immediate reconnect (no backoff).

class
LangSmithValidationError

Raised when request validation fails.

This includes:

  • Resource values exceeding server-defined limits (CPU, memory, storage)
  • Invalid resource units
  • Invalid name formats
class
Sandbox

Represents an active sandbox for running commands and file operations.

This class is typically obtained from SandboxClient.createSandbox() and provides methods for command execution and file I/O within the sandbox environment.

class
SandboxClient

Client for interacting with the Sandbox Server API.

This client provides a simple interface for managing sandboxes and snapshots.

Interfaces

interface
CaptureSnapshotOptions

Options for capturing a snapshot from a running sandbox.

interface
CreateDockerfileSnapshotOptions

Options for creating a snapshot from a local Dockerfile context.

interface
CreateSandboxOptions

Options for creating a sandbox.

interface
CreateSnapshotOptions

Options for creating a snapshot from a Docker image.

interface
ExecutionResult

Result of executing a command in a sandbox.

interface
GCSMountConfig

GCS configuration for a sandbox mount.

interface
GCSMountSpec

GCS-backed sandbox mount specification.

interface
GitMountConfig

Git configuration for a sandbox mount.

interface
GitMountRefSpec

Git ref selected for a sandbox mount.

interface
GitMountSpec

Git-backed sandbox mount specification.

interface
ListSnapshotsOptions

Options for listing snapshots. All fields are optional and independent.

The backend always paginates: when limit is omitted the server applies a default page size (currently 50), so a single call will not necessarily return every snapshot visible to the caller's tenant.

interface
MountCacheConfig

Optional per-mount cache configuration supported by bucket mounts.

interface
OutputChunk

A single chunk of streaming output from command execution.

interface
ResourceStatus

Lightweight provisioning status for any async-created resource.

interface
RunOptions

Options for running a command in a sandbox.

interface
S3MountConfig

S3 configuration for a sandbox mount. Field names are snake_case so the object is wire-compatible with the backend MountSpec type.

interface
S3MountSpec

S3-backed sandbox mount specification.

interface
SandboxAccessControl

Network access-control rules for a sandbox's proxy sidecar.

Supported pattern types: exact domains, globs (e.g. *.example.com), IPs, CIDR ranges (e.g. 10.0.0.0/8), and regex (~pattern).

Only one of allow_list and deny_list may be populated.

interface
SandboxAwsAuthRule

AWS auth rule for sandbox proxy SigV4 signing.

interface
SandboxAwsMountAuthConfig

AWS credentials used by the backend to authenticate S3 mounts.

interface
SandboxClientConfig

Configuration options for the SandboxClient.

interface
SandboxData

Data representing a sandbox instance from the API.

interface
SandboxGcpAuthRule

GCP auth rule for sandbox proxy OAuth bearer injection.

interface
SandboxGcpMountAuthConfig

GCP credentials used by the backend to authenticate GCS mounts.

interface
SandboxMountAuthConfig

Provider auth blocks for sandbox mounts.

interface
SandboxMountConfig

Public mount config sent to the sandbox API.

interface
SandboxProxyConfig

Full proxy configuration forwarded to the sandbox server as-is (snake_case so it's wire-compatible with the backend). Mirrors the server's ProxyConfig type.

interface
SandboxProxySecret

Secret value reference for sandbox proxy rules.

interface
Snapshot

Represents a sandbox snapshot.

Snapshots are built from Docker images or captured from running sandboxes. They are used to create new sandboxes.

interface
StartSandboxOptions

Options for starting a stopped sandbox.

interface
UpdateSandboxOptions

Options for updating a sandbox (name and/or retention settings).

interface
WaitForSandboxOptions

Options for waiting for a sandbox to become ready.

interface
WaitForSnapshotOptions

Options for waiting for a snapshot to become ready.

interface
WsMessage

Internal WebSocket message type from the server.

interface
WsRunOptions

Options for the low-level WebSocket stream functions.

Type Aliases

typeAlias
SandboxMount: S3MountSpec | GCSMountSpec | GitMountSpec

Sandbox mount specification.

typeAlias
SandboxMountAuth: SandboxAwsAuthRule | SandboxGcpAuthRule

Provider auth helper output accepted by mountConfig.

typeAlias
SandboxProxyRule: SandboxAwsAuthRule | SandboxGcpAuthRule | Record<string, unknown>

Proxy rule accepted by the sandbox proxy config.

View source on GitHub