# server_session

> **Function** in `deepagents_cli`

📖 [View in docs](https://reference.langchain.com/python/deepagents-cli/server_manager/server_session)

Async context manager that starts a server and guarantees cleanup.

Wraps `start_server_and_get_agent` so callers don't need to duplicate the
try/finally pattern for stopping the server.

## Signature

```python
server_session(
    *,
    assistant_id: str,
    model_name: str | None = None,
    model_params: dict[str, Any] | None = None,
    auto_approve: bool = False,
    interrupt_shell_only: bool = False,
    shell_allow_list: list[str] | None = None,
    sandbox_type: str = 'none',
    sandbox_id: str | None = None,
    sandbox_setup: str | None = None,
    enable_shell: bool = True,
    enable_ask_user: bool = False,
    mcp_config_path: str | None = None,
    no_mcp: bool = False,
    trust_project_mcp: bool | None = None,
    interactive: bool = True,
    host: str = '127.0.0.1',
    port: int = 2024,
) -> AsyncIterator[tuple[RemoteAgent, ServerProcess]]
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `assistant_id` | `str` | Yes | Agent identifier. |
| `model_name` | `str \| None` | No | Model spec string. (default: `None`) |
| `model_params` | `dict[str, Any] \| None` | No | Extra model kwargs. (default: `None`) |
| `auto_approve` | `bool` | No | Auto-approve all tools. (default: `False`) |
| `interrupt_shell_only` | `bool` | No | Validate shell commands via middleware instead of HITL. (default: `False`) |
| `shell_allow_list` | `list[str] \| None` | No | Restrictive shell allow-list for `ShellAllowListMiddleware`. (default: `None`) |
| `sandbox_type` | `str` | No | Sandbox type. (default: `'none'`) |
| `sandbox_id` | `str \| None` | No | Existing sandbox ID to reuse. (default: `None`) |
| `sandbox_setup` | `str \| None` | No | Path to setup script for the sandbox. (default: `None`) |
| `enable_shell` | `bool` | No | Enable shell execution tools. (default: `True`) |
| `enable_ask_user` | `bool` | No | Enable ask_user tool. (default: `False`) |
| `mcp_config_path` | `str \| None` | No | Path to MCP config. (default: `None`) |
| `no_mcp` | `bool` | No | Disable MCP. (default: `False`) |
| `trust_project_mcp` | `bool \| None` | No | Trust project MCP servers. (default: `None`) |
| `interactive` | `bool` | No | Whether the agent is interactive. (default: `True`) |
| `host` | `str` | No | Server host. (default: `'127.0.0.1'`) |
| `port` | `int` | No | Server port. (default: `2024`) |

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/a9e6e4f7ad7fe161dd9affc3d74bb19784aca70b/libs/cli/deepagents_cli/server_manager.py#L287)