# run_ws_stream

> **Function** in `langsmith`

📖 [View in docs](https://reference.langchain.com/python/langsmith/sandbox/_ws_execute/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.

## Signature

```python
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,
    idle_timeout: int = 300,
    kill_on_disconnect: bool = False,
    ttl_seconds: int = 600,
    pty: bool = False,
    headers: Optional[Mapping[str, str]] = None,
) -> tuple[Iterator[dict], _WSStreamControl]
```

---

[View source on GitHub](https://github.com/langchain-ai/langsmith-sdk/blob/19dc497a3d89638e4cc35db72ea1c29cad35cbbf/python/langsmith/sandbox/_ws_execute.py#L210)