# run_command_handler

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/hooks/runner/run_command_handler)

Run one hook command with bounded time and captured output.

## Signature

```python
run_command_handler(
    handler: HookHandler,
    payload: bytes,
    *,
    cwd: Path,
    default_timeout: float = DEFAULT_COMMAND_TIMEOUT_SECONDS,
    max_output_bytes: int = MAX_HOOK_OUTPUT_BYTES,
    env: dict[str, str] | None = None,
) -> HandlerResult
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `handler` | `HookHandler` | Yes | Snapshotted command handler. |
| `payload` | `bytes` | Yes | Validated JSON sent to stdin. |
| `cwd` | `Path` | Yes | Working directory inherited from the invocation. |
| `default_timeout` | `float` | No | Timeout used when the handler has no override. (default: `DEFAULT_COMMAND_TIMEOUT_SECONDS`) |
| `max_output_bytes` | `int` | No | Maximum retained bytes for each output stream. (default: `MAX_HOOK_OUTPUT_BYTES`) |
| `env` | `dict[str, str] \| None` | No | Optional environment override. Defaults to a sanitized copy of the process environment. (default: `None`) |

## Returns

`HandlerResult`

Validated protocol output and structured diagnostics.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/4bfa52000ef65ac623d8ada0cb67f67cbdd663ea/libs/code/deepagents_code/hooks/runner.py#L46)