LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Agent
  • Middleware
  • Backends
  • Sandboxes
  • Skills
  • Subagents
  • Configuration
  • Types
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
  • Vitest
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewAgentMiddlewareBackendsSandboxesSkillsSubagentsConfigurationTypes
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
Vitest
Language
Theme
JavaScriptdeepagentsbackendsLocalShellBackend
Class●Since v1.8

LocalShellBackend

Copy
class LocalShellBackend

Bases

FilesystemBackend

Constructors

Properties

Methods

Inherited fromFilesystemBackend

Properties

PcwdPvirtualMode: boolean
—

Enable virtual path mode for filesystem operations.

Methods

MdownloadFiles→ MaybePromise<FileDownloadResponse[]>
—

Download multiple files from the sandbox.

M
View source on GitHub
edit
→ Promise<EditResult>
—

Edit a file by replacing string occurrences.

Mglob→ Promise<GlobResult>
—

Structured glob matching returning FileInfo objects.

Mgrep→ Promise<GrepResult>
—

Search for a literal text pattern in files using grep.

Mls→ Promise<LsResult>
—

List files and directories in the specified directory (non-recursive).

Mread→ Promise<ReadResult>
—

Read file content with line numbers.

MreadRaw→ Promise<ReadRawResult>
—

Read file content as raw FileData.

MuploadFiles→ MaybePromise<FileUploadResponse[]>
—

Upload multiple files to the sandbox.

Mwrite→ Promise<WriteResult>
—

Create a new file with content.

Example

constructor
constructor
property
cwd: string
property
virtualMode: boolean
property
id: string
property
isInitialized: boolean
property
isRunning: boolean
method
close→ Promise<void>
method
downloadFiles→ MaybePromise<FileDownloadResponse[]>
method
edit→ Promise<EditResult>
method
execute→ MaybePromise<ExecuteResponse>
method
glob→ Promise<GlobResult>
method
grep→ Promise<GrepResult>
method
initialize→ Promise<void>
method
ls→ Promise<LsResult>
method
read→ Promise<ReadResult>
method
readRaw→ Promise<ReadRawResult>
method
uploadFiles→ MaybePromise<FileUploadResponse[]>
method
write→ Promise<WriteResult>
method
create→ Promise<LangSmithSandbox>

Filesystem backend with unrestricted local shell command execution.

This backend extends FilesystemBackend to add shell command execution capabilities. Commands are executed directly on the host system without any sandboxing, process isolation, or security restrictions.

Security Warning: This backend grants agents BOTH direct filesystem access AND unrestricted shell execution on your local machine. Use with extreme caution and only in appropriate environments.

Appropriate use cases:

  • Local development CLIs (coding assistants, development tools)
  • Personal development environments where you trust the agent's code
  • CI/CD pipelines with proper secret management

Inappropriate use cases:

  • Production environments (e.g., web servers, APIs, multi-tenant systems)
  • Processing untrusted user input or executing untrusted code

Use StateBackend, StoreBackend, or extend BaseSandbox for production.

Enable virtual path mode for filesystem operations. When true, treats rootDir as a virtual root filesystem. Does NOT restrict shell commands.

Unique identifier for the sandbox backend

Delete this sandbox and mark it as no longer running.

After calling this, isRunning will be false and the sandbox cannot be used again.

Download multiple files from the sandbox. Implementations must support partial success.

Edit a file by replacing string occurrences.

Uses downloadFiles() to read, performs string replacement in TypeScript, then uploadFiles() to write back. No runtime needed on the sandbox host.

Memory-conscious: releases intermediate references early so the GC can reclaim buffers before the next large allocation is made.

Execute a command in the sandbox. This is the only method concrete implementations must provide.

Structured glob matching returning FileInfo objects.

Uses pure POSIX shell (find + stat) via execute() to list all files, then applies glob-to-regex matching in TypeScript. No Python or Node.js needed on the sandbox host.

Glob patterns are matched against paths relative to the search base:

  • * matches any characters except /
  • ** matches any characters including / (recursive)
  • ? matches a single character except /
  • [...] character classes

Search for a literal text pattern in files using grep.

Initialize the backend by ensuring the rootDir exists.

Creates the rootDir (and any parent directories) if it does not already exist. Safe to call on an existing directory. Must be called before execute(), or use the static LocalShellBackend.create() factory.

List files and directories in the specified directory (non-recursive).

Uses pure POSIX shell (find + stat) via execute() — works on any Linux including Alpine. No Python or Node.js needed.

Read file content with line numbers.

Uses pure POSIX shell (awk) via execute() — only the requested slice is returned over the wire, making this efficient for large files. Works on any Linux including Alpine (no Python or Node.js needed).

Read file content as raw FileData.

Uses downloadFiles() directly — no runtime needed on the sandbox host.

Upload multiple files to the sandbox. Implementations must support partial success.

Create a new file with content.

Uses downloadFiles() to check existence and uploadFiles() to write. No runtime needed on the sandbox host.

Create and return a new LangSmithSandbox in one step.

This is the recommended way to create a sandbox — no need to import anything from langsmith/experimental/sandbox directly.

Copy
import { LocalShellBackend } from "@langchain/deepagents";

// Create backend with explicit environment
const backend = new LocalShellBackend({
  rootDir: "/home/user/project",
  env: { PATH: "/usr/bin:/bin" },
});

// Execute shell commands (runs directly on host)
const result = await backend.execute("ls -la");
console.log(result.output);
console.log(result.exitCode);

// Use filesystem operations (inherited from FilesystemBackend)
const content = await backend.read("/README.md");
await backend.write("/output.txt", "Hello world");

// Inherit all environment variables
const backend2 = new LocalShellBackend({
  rootDir: "/home/user/project",
  inheritEnv: true,
});