LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Client
  • AsyncClient
  • Run Helpers
  • Run Trees
  • Evaluation
  • Schemas
  • Utilities
  • Wrappers
  • Anonymizer
  • Testing
  • Expect API
  • Middleware
  • Pytest Plugin
  • Deployment SDK
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewClientAsyncClientRun HelpersRun TreesEvaluationSchemasUtilitiesWrappersAnonymizerTestingExpect APIMiddlewarePytest PluginDeployment SDK
Language
Theme
Pythonlangsmithsandbox_async_clientAsyncSandboxClient
Class●Since v0.6

AsyncSandboxClient

Copy
AsyncSandboxClient(
  self,
  *,
  api_endpoint: Optional[str] = None,
  timeout: float

Used in Docs

  • Sandbox SDK usage

Constructors

Methods

View source on GitHub
=
10.0
,
api_key
:
Optional
[
str
]
=
None
,
max_retries
:
int
=
3
,
headers
:
Optional
[
Mapping
[
str
,
str
]
]
=
None
)

Parameters

NameTypeDescription
api_endpointOptional[str]
Default:None

Full URL of the sandbox API endpoint. If not provided, derived from LANGSMITH_ENDPOINT environment variable.

timeoutfloat
Default:10.0

Default HTTP timeout in seconds.

api_keyOptional[str]
Default:None
max_retriesint
Default:3
headersOptional[Mapping[str, str]]
Default:None
constructor
__init__
NameType
api_endpointOptional[str]
timeoutfloat
api_keyOptional[str]
max_retriesint
headersOptional[Mapping[str, str]]
method
aclose

Close the async HTTP client.

method
sandbox

Create a sandbox and return an AsyncSandbox instance.

This is the primary method for creating sandboxes. Use it as an async context manager for automatic cleanup:

async with await client.sandbox(snapshot_id="<uuid>") as sandbox:
    result = await sandbox.run("echo hello")

# Resolve by snapshot name instead of ID:
async with await client.sandbox(snapshot_name="my-snap") as sandbox:
    result = await sandbox.run("echo hello")

The sandbox is automatically deleted when exiting the context manager. For sandboxes with manual lifecycle management, use create_sandbox().

method
create_sandbox

Create a new Sandbox.

The sandbox is NOT automatically deleted. Use delete_sandbox() for cleanup, or use sandbox() for automatic cleanup with a context manager.

method
get_sandbox

Get a Sandbox by name.

The sandbox is NOT automatically deleted. Use delete_sandbox() for cleanup.

method
list_sandboxes

List all Sandboxes.

method
update_sandbox

Update a sandbox's properties.

method
delete_sandbox

Delete a Sandbox.

method
get_sandbox_status

Get the provisioning status of a sandbox.

This is a lightweight endpoint designed for high-frequency polling during sandbox provisioning. It returns only the status fields without full sandbox data.

method
service

Get an authenticated URL for a service running inside a sandbox.

Returns an :class:AsyncServiceURL whose async accessors auto-refresh the token transparently before it expires. The object also provides async HTTP helper methods (.get, .post, etc.) that inject the authentication header automatically.

method
wait_for_sandbox

Poll until a sandbox reaches "ready" or "failed" status.

Uses the lightweight status endpoint for polling, then fetches the full sandbox data once ready.

method
start_sandbox

Start a stopped sandbox and wait until ready.

method
stop_sandbox

Stop a running sandbox (preserves sandbox files for later restart).

method
create_snapshot

Build a snapshot from a Docker image.

Blocks until the snapshot is ready (polls with 2s interval).

method
capture_snapshot

Capture a snapshot from a running sandbox.

Blocks until the snapshot is ready (polls with 2s interval).

method
get_snapshot

Get a snapshot by ID.

method
list_snapshots

List snapshots.

The backend always paginates this endpoint. When limit is omitted the server applies a default page size (currently 50), so a single call is not guaranteed to return every snapshot. To iterate through all results, repeat the call with increasing offset values (or an explicit limit) until fewer than limit snapshots come back.

method
delete_snapshot

Delete a snapshot.

method
wait_for_snapshot

Poll until a snapshot reaches "ready" or "failed" status.

Async client for interacting with the Sandbox Server API.

This client provides an async interface for managing sandboxes and snapshots.

Example:

Uses LANGSMITH_ENDPOINT and LANGSMITH_API_KEY from environment

async with AsyncSandboxClient() as client: # Create a sandbox with the default runtime and run commands async with await client.sandbox() as sandbox: result = await sandbox.run("python --version") print(result.stdout)

API key for authentication. If not provided, uses LANGSMITH_API_KEY environment variable.

Maximum number of retries for transient errors (502, 503, 504), rate limits (429), and connection failures. Set to 0 to disable retries. Default: 3.

Optional default headers attached to every request on this client, including the data-plane /execute HTTP endpoint and the /execute/ws WebSocket upgrade. Use this to pass additional auth headers (e.g. X-Service-Key).