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_sandboxAsyncSandboxrun
Method●Since v0.6

run

Copy
run(
  self,
  command: str,
  *,
  timeout: int = 60,
  env
View source on GitHub
:
Optional
[
dict
[
str
,
str
]
]
=
None
,
cwd
:
Optional
[
str
]
=
None
,
shell
:
str
=
'/bin/bash'
,
on_stdout
:
Optional
[
Callable
[
[
str
]
,
Any
]
]
=
None
,
on_stderr
:
Optional
[
Callable
[
[
str
]
,
Any
]
]
=
None
,
idle_timeout
:
int
=
300
,
kill_on_disconnect
:
bool
=
False
,
ttl_seconds
:
int
=
600
,
pty
:
bool
=
False
,
headers
:
RequestHeaders
=
None
,
wait
:
bool
=
True
)
->
Union
[
ExecutionResult
,
AsyncCommandHandle
]

Parameters

NameTypeDescription
command*str

Shell command to execute.

timeoutint
Default:60

Command timeout in seconds.

envOptional[dict[str, str]]
Default:None
cwdOptional[str]
Default:None
shellstr
Default:'/bin/bash'
on_stdoutOptional[Callable[[str], Any]]
Default:None
on_stderrOptional[Callable[[str], Any]]
Default:None
idle_timeoutint
Default:300
kill_on_disconnectbool
Default:False
ttl_secondsint
Default:600
ptybool
Default:False
waitbool
Default:True

Execute a command in the sandbox asynchronously.

Environment variables to set for the command.

Working directory for command execution. If None, uses sandbox default.

Shell to use for command execution. Defaults to "/bin/bash".

Callback invoked with each stdout chunk as it arrives. Blocks until the command completes and returns ExecutionResult. Cannot be combined with wait=False.

Callback invoked with each stderr chunk as it arrives. Blocks until the command completes and returns ExecutionResult. Cannot be combined with wait=False.

Idle timeout in seconds. If the command has no connected clients for this duration, it is killed. Defaults to 300 (5 minutes). Set to -1 for no idle timeout. Only applies to WebSocket execution.

If True, kill the command immediately when the last client disconnects. Defaults to False (command continues running and can be reconnected to).

How long (in seconds) a finished command's session is kept for reconnection. Defaults to 600 (10 minutes). Set to -1 to keep indefinitely.

If True, allocate a pseudo-terminal for the command. Useful for commands that require a TTY (e.g., interactive programs, commands that use terminal control codes). Defaults to False.

If True (default), block until the command completes and return ExecutionResult. If False, return an AsyncCommandHandle immediately for streaming output, kill, stdin input, and reconnection. Cannot be combined with on_stdout/on_stderr callbacks.