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
  • Traceable
  • Jestlike
  • Vercel
  • Anthropic
  • Sandbox
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangSmith
ClientRun TreesTraceableEvaluationSchemasLangchainJestVitestWrappersAnonymizerTraceableJestlikeVercelAnthropicSandbox
Language
Theme
JavaScriptlangsmithexperimentalsandboxCommandHandle
Class●Since v0.7

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)
Copy
class CommandHandle

Example

Copy
const handle = await sandbox.run("make build", { timeout: 600, wait: false });

for await (const chunk of handle) {  // auto-reconnects on transient errors
  process.stdout.write(chunk.data);
}

const result = await handle.result;
console.log(`Exit code: ${result.exit_code}`);

Properties

property
BACKOFF_BASE: number
property
BACKOFF_MAX: number
property
MAX_AUTO_RECONNECTS: number
property
commandId: string | null
property
lastStderrOffset: number
property
lastStdoutOffset: number
property
pid: number | null
property
result: Promise<ExecutionResult>

Methods

method
_ensureStarted→ Promise<void>

Read the 'started' message to populate commandId and pid.

Must be called (and awaited) before iterating for new executions.

method
[asyncIterator]→ AsyncIterableIterator<OutputChunk>

Async iterate over output chunks with auto-reconnect on transient errors.

Reconnect strategy:

  • 1001 Going Away (hot-reload): immediate reconnect, no delay
  • Other SandboxConnectionError: exponential backoff (0.5s, 1s, 2s...)
  • After kill(): no reconnect, error propagates
method
kill

Send a kill signal to the running command (SIGKILL).

The server kills the entire process group. The stream will subsequently yield an exit message with a non-zero exit code.

method
reconnect→ Promise<CommandHandle>

Reconnect to this command from the last known offsets.

Returns a new CommandHandle that resumes output from where this one left off.

method
sendInput

Write data to the command's stdin.

View source on GitHub