Skip to content

mount_security

diapason.sandbox.mount_security

Mount validation and security for container sandboxes.

Port of NanoClaw's mount-security.ts — validates bind mounts against an allowlist and blocks paths containing sensitive files.

AllowedRoot dataclass

An allowed mount root with optional read-only constraint.

MountAllowlist dataclass

Allowlist for container mounts.

load_mount_allowlist(path)

Load a mount allowlist from a JSON file.

Expected format::

{
    "roots": [
        {"path": "/home/user/projects", "read_only": false},
        {"path": "/data", "read_only": true}
    ],
    "blocked_patterns": [".ssh", ".env", "*.pem"]
}

If blocked_patterns is omitted, :data:DEFAULT_BLOCKED_PATTERNS is used.

validate_mount(mount_path, allowlist)

Validate a single mount path against the allowlist.

Returns True if the mount is allowed, False otherwise.

validate_mounts(mounts, allowlist)

Validate a list of mount paths. Returns only valid mounts.

Raises :class:ValueError for any blocked mount.