# How to Configure `self.mounts` in DockerSandboxService

The `self.mounts` attribute in `DockerSandboxService` is a list of `VolumeMount` objects that define volume mounts for Docker containers.

## VolumeMount Structure

Each `VolumeMount` has three fields:

- `host_path` (str): Path on the host machine
- `container_path` (str): Path inside the container
- `mode` (str): Mount mode - `'rw'` (read-write, default) or `'ro'` (read-only)

## Configuration Methods

### Method 1: Programmatic Configuration (Recommended)

Modify `openhands/app_server/config.py` to pass mounts when creating `DockerSandboxServiceInjector`:

```python
from openhands.app_server.sandbox.docker_sandbox_service import (
    DockerSandboxServiceInjector,
    VolumeMount,
)

# In config_from_env() function, around line 178:
config.sandbox = DockerSandboxServiceInjector(
    mounts=[
        VolumeMount(
            host_path='/path/on/host',
            container_path='/path/in/container',
            mode='rw'
        ),
        VolumeMount(
            host_path='/another/host/path',
            container_path='/another/container/path',
            mode='ro'  # read-only mount
        ),
    ]
)
```

### Method 2: Environment Variables (Requires Code Modification)

**Note:** Currently, `DockerSandboxServiceInjector` is instantiated directly in `config_from_env()` without reading from environment variables. To use environment variables, you would need to modify the code to read from env vars.

If you modify `openhands/app_server/config.py` to read from environment variables, you could use:

```bash
export OH_SANDBOX_MOUNTS='[{"host_path": "/path/on/host", "container_path": "/path/in/container", "mode": "rw"}]'
```

The configuration system uses Python literal syntax (`literal_eval`) for lists of Pydantic models. Each dictionary in the list will be converted to a `VolumeMount` object.

**Note:** The `mode` field is optional and defaults to `'rw'` if not specified.

### Method 3: Configuration File (TOML)

If you configure `config.sandbox` directly in your TOML config file, you can set mounts:

```toml
[sandbox]
# Note: This requires the sandbox injector to be properly configured
# You may need to set it as a full object depending on your config structure
```

However, the current implementation instantiates `DockerSandboxServiceInjector()` directly, so TOML configuration may require additional code changes to work properly.

## Example Use Cases

### Example 1: Mount a workspace directory

```python
mounts=[
    VolumeMount(
        host_path='/home/user/workspace',
        container_path='/workspace',
        mode='rw'
    )
]
```

### Example 2: Mount multiple directories with different permissions

```python
mounts=[
    VolumeMount(
        host_path='/home/user/code',
        container_path='/workspace',
        mode='rw'
    ),
    VolumeMount(
        host_path='/home/user/readonly-data',
        container_path='/data',
        mode='ro'  # Read-only mount
    )
]
```

### Example 3: Mount a Docker named volume

```python
mounts=[
    VolumeMount(
        host_path='my-named-volume',  # Docker named volume
        container_path='/data',
        mode='rw'
    )
]
```

## How It's Used

The mounts are converted to Docker volume bindings in the `start_sandbox` method (lines 327-334):

```python
volumes = {
    mount.host_path: {
        'bind': mount.container_path,
        'mode': mount.mode,
    }
    for mount in self.mounts
}
```

These volumes are then passed to `docker_client.containers.run()` when creating containers.

## Default Behavior

By default, `mounts` is an empty list (`Field(default_factory=list)`), meaning no additional volumes are mounted beyond what's configured in the Docker image itself.
