Skip to main content
Sandboxes are in private preview. APIs and features may change as we iterate. Sign up for the waitlist to get access.
The LangSmith SDK provides a programmatic interface to create and interact with sandboxes.

Install

The [sandbox] extra for Python installs websockets, which enables real-time streaming and timeout=0. Without it, run() falls back to HTTP automatically. For TypeScript, install the optional ws package for WebSocket streaming:

Create and run a sandbox

Run commands

Every run() call returns an ExecutionResult with stdout, stderr, exit_code, and success.

Stream output

For long-running commands, stream output in real time using callbacks or a CommandHandle.

Stream with callbacks

Stream with CommandHandle

Set wait=False to get a CommandHandle for full control over the output stream.

Send stdin and kill commands

Kill a running command:

Reconnect to a running command

If a client disconnects, reconnect using the command ID:

File operations

Read and write files in the sandbox:

Command lifecycle and TTL

The sandbox daemon manages command session lifecycles with two timeout mechanisms:
  • Session TTL (finished commands): After a command finishes, its session remains in memory for a TTL period. During this window you can reconnect to retrieve output. After the TTL expires, the session is cleaned up.
  • Idle timeout (running commands): Running commands with no connected clients are killed after an idle timeout (default: 5 minutes). The idle timer resets each time a client connects. Set to -1 for no idle timeout.

Combine lifecycle options

Set kill_on_disconnect=True (Python) or killOnDisconnect: true (TypeScript) to kill the command immediately when the last client disconnects, instead of waiting for the idle timeout.

TCP tunnels (Python)

Access any TCP service running inside a sandbox as if it were local. The tunnel opens a local TCP port and forwards connections through a WebSocket to the target port inside the sandbox.
Tunnels work with any TCP service (Redis, HTTP servers, etc.) and you can open multiple tunnels simultaneously:

Async support (Python)

The Python SDK provides a full async client:

Error handling

Both SDKs provide typed exceptions for specific error handling:
For more details, see the sandbox SDK reference on GitHub for Python or TypeScript.