# Sandbox

> **Class** in `langsmith`

📖 [View in docs](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox)

Represents an active sandbox for running commands and file operations.

This class is typically obtained from SandboxClient.sandbox() and supports
the context manager protocol for automatic cleanup.

## Signature

```python
Sandbox(
    self,
    name: str,
    dataplane_url: Optional[str] = None,
    id: Optional[str] = None,
    status: str = 'ready',
    status_message: Optional[str] = None,
    created_at: Optional[str] = None,
    updated_at: Optional[str] = None,
    idle_ttl_seconds: Optional[int] = None,
    delete_after_stop_seconds: Optional[int] = None,
    stopped_at: Optional[str] = None,
    snapshot_id: Optional[str] = None,
    vcpus: Optional[int] = None,
    mem_bytes: Optional[int] = None,
    fs_capacity_bytes: Optional[int] = None,
    run_config: Optional[RunConfig] = None,
    access_delegation: Optional[AccessDelegation] = None,
    _client: SandboxClient = None,
    _auto_delete: bool = True,
)
```

## Description

**Example:**

with client.sandbox(snapshot_id="<snapshot-uuid>") as sandbox:
result = sandbox.run("python --version")
print(result.stdout)

## Constructors

```python
__init__(
    self,
    name: str,
    dataplane_url: Optional[str] = None,
    id: Optional[str] = None,
    status: str = 'ready',
    status_message: Optional[str] = None,
    created_at: Optional[str] = None,
    updated_at: Optional[str] = None,
    idle_ttl_seconds: Optional[int] = None,
    delete_after_stop_seconds: Optional[int] = None,
    stopped_at: Optional[str] = None,
    snapshot_id: Optional[str] = None,
    vcpus: Optional[int] = None,
    mem_bytes: Optional[int] = None,
    fs_capacity_bytes: Optional[int] = None,
    run_config: Optional[RunConfig] = None,
    access_delegation: Optional[AccessDelegation] = None,
    _client: SandboxClient = None,
    _auto_delete: bool = True,
) -> None
```

| Name | Type |
|------|------|
| `name` | `str` |
| `dataplane_url` | `Optional[str]` |
| `id` | `Optional[str]` |
| `status` | `str` |
| `status_message` | `Optional[str]` |
| `created_at` | `Optional[str]` |
| `updated_at` | `Optional[str]` |
| `idle_ttl_seconds` | `Optional[int]` |
| `delete_after_stop_seconds` | `Optional[int]` |
| `stopped_at` | `Optional[str]` |
| `snapshot_id` | `Optional[str]` |
| `vcpus` | `Optional[int]` |
| `mem_bytes` | `Optional[int]` |
| `fs_capacity_bytes` | `Optional[int]` |
| `run_config` | `Optional[RunConfig]` |
| `access_delegation` | `Optional[AccessDelegation]` |
| `_client` | `SandboxClient` |
| `_auto_delete` | `bool` |


## Properties

- `name`
- `dataplane_url`
- `id`
- `status`
- `status_message`
- `created_at`
- `updated_at`
- `idle_ttl_seconds`
- `delete_after_stop_seconds`
- `stopped_at`
- `snapshot_id`
- `vcpus`
- `mem_bytes`
- `fs_capacity_bytes`
- `run_config`
- `access_delegation`

## Methods

- [`from_dict()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/from_dict)
- [`to_async()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/to_async)
- [`run()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/run)
- [`reconnect()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/reconnect)
- [`write()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/write)
- [`read()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/read)
- [`stat()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/stat)
- [`read_range()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/read_range)
- [`glob()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/glob)
- [`ls()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/ls)
- [`grep()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/grep)
- [`tunnel()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/tunnel)
- [`service()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/service)
- [`generate_download_url()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/generate_download_url)
- [`start()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/start)
- [`stop()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/stop)
- [`delete()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/delete)
- [`capture_snapshot()`](https://reference.langchain.com/python/langsmith/sandbox/_sandbox/Sandbox/capture_snapshot)

---

[View source on GitHub](https://github.com/langchain-ai/langsmith-python/blob/15dd2a789f976bbbafd803b26d0f25c08b5ed527/src/langsmith/sandbox/_sandbox.py#L83)