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_ws_executerun_ws_stream
Function●Since v0.7

run_ws_stream

Execute a command over WebSocket, yielding raw message dicts.

Returns a tuple of (message_iterator, control). The control object provides send_kill() and send_input() methods for the CommandHandle.

The iterator yields dicts with a "type" field:

  • {"type": "started", "command_id": "...", "pid": N}
  • {"type": "stdout", "data": "...", "offset": N}
  • {"type": "stderr", "data": "...", "offset": N}
  • {"type": "exit", "exit_code": N}

If on_stdout/on_stderr callbacks are provided, they are invoked as data arrives in addition to yielding the messages.

Copy
run_ws_stream(
  dataplane_url: str,
  api_key: Optional[str],
  command: str,
  *,
  timeout: int = 60,
  env: 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
) -> tuple[Iterator[dict], _WSStreamControl]
View source on GitHub