Secure, Fast, and Extensible Sandbox runtime for AI agents.
fix(server): honor POSIX root in host path allowlists
Yzzz880d5a9dfabc15
diff --git a/docs/getting-started/configuration.md b/docs/getting-started/configuration.mdindex 603b34d46..a80dcf56d 100644--- a/docs/getting-started/configuration.md+++ b/docs/getting-started/configuration.md@@ -64,6 +64,10 @@ If `server.api_key` is empty, the server runs without authentication. In non-intFor the full configuration reference with all keys and defaults, see the [server configuration.md](https://github.com/opensandbox-group/OpenSandbox/blob/main/server/configuration.md).+## Host Bind Mounts++`storage.allowed_host_paths` entries allow a host path and its descendants, with directory boundaries preserved. An explicit POSIX root entry (`/`) allows all POSIX host paths, while a Windows drive root such as `D:/` allows paths on that drive only. Prefer narrower directory prefixes for shared environments; an empty list rejects all host bind mounts.+## Sandbox Expiration`server.max_sandbox_timeout_seconds` limits the `timeout` supplied when creating a sandbox. If configured, it must be at least `60` seconds; omit it to disable the creation-time upper bound. It does not limit renewal requests or the total lifetime of a sandbox.diff --git a/server/opensandbox_server/services/validators.py b/server/opensandbox_server/services/validators.pyindex f85c5c86a..3741b2ad7 100644--- a/server/opensandbox_server/services/validators.py+++ b/server/opensandbox_server/services/validators.py@@ -423,7 +423,7 @@ def ensure_valid_host_path(norm_path = _normalize_prefix_path(path)is_allowed = any(norm_path == _normalize_prefix_path(prefix)- or norm_path.startswith(_normalize_prefix_path(prefix) + "/")+ or norm_path.startswith(_normalize_prefix_path(prefix).rstrip("/") + "/")for prefix in allowed_prefixes)if not is_allowed:diff --git a/server/tests/test_validators.py b/server/tests/test_validators.pyindex dbe369594..f0528d640 100644--- a/server/tests/test_validators.py+++ b/server/tests/test_validators.py@@ -351,6 +351,36 @@ class TestEnsureValidHostPath:allowed = ["/data/opensandbox"]assert ensure_valid_host_path("/data/opensandbox", allowed) is None+ @pytest.mark.parametrize("path", ["/", "/data", "/data/opensandbox"])+ def test_allowed_posix_root_prefix(self, path):+ assert ensure_valid_host_path(path, ["/"]) is None++ @pytest.mark.parametrize("prefix", ["D:/", "D:\\"])+ @pytest.mark.parametrize("path", ["d:/", "D:/data", r"d:\data\opensandbox"])+ def test_allowed_windows_drive_root_prefix(self, path, prefix):+ assert ensure_valid_host_path(path, [prefix]) is None++ @pytest.mark.parametrize(+ "path,prefix",+ [("D:/data", "/"), ("/data", "D:/"), ("E:/data", "D:/")],+ )+ def test_root_prefix_does_not_allow_other_roots(self, path, prefix):+ with pytest.raises(HTTPException) as exc_info:+ ensure_valid_host_path(path, [prefix])+ assert exc_info.value.status_code == 400+ detail = exc_info.value.detail+ assert isinstance(detail, dict)+ assert detail.get("code") == SandboxErrorCodes.HOST_PATH_NOT_ALLOWED++ @pytest.mark.parametrize("path", ["/data", "D:/data"])+ def test_empty_allowlist_rejects_host_paths(self, path):+ with pytest.raises(HTTPException) as exc_info:+ ensure_valid_host_path(path, [])+ assert exc_info.value.status_code == 400+ detail = exc_info.value.detail+ assert isinstance(detail, dict)+ assert detail.get("code") == SandboxErrorCodes.HOST_PATH_NOT_ALLOWED+def test_allowed_prefix_match_windows_paths(self):allowed = [r"D:\sandbox-mnt"]assert ensure_valid_host_path(r"D:\sandbox-mnt\ReMe", allowed) is None@@ -540,6 +570,13 @@ class TestEnsureVolumesValid:assert exc_info.value.status_code == 400assert exc_info.value.detail["code"] == SandboxErrorCodes.HOST_PATH_NOT_ALLOWED+ def test_host_path_root_allowlist_accepts_descendant(self):+ volume = Volume.model_validate(+ {"name": "data", "host": {"path": "/data"}, "mountPath": "/mnt/data"}+ )++ assert ensure_volumes_valid([volume], allowed_host_prefixes=["/"]) is None+def test_ossfs_invalid_version_rejected_by_schema(self):from pydantic import ValidationError