The platform for continuously improving AI agents.
Create the native workspace root only when a workspace is written (#327)
Freyam Mehta4715af065dc8
diff --git a/sandbox/workspaces.py b/sandbox/workspaces.pyindex fb873238..2a5afca2 100644--- a/sandbox/workspaces.py+++ b/sandbox/workspaces.py@@ -57,9 +57,7 @@ RESTARTED = "The kernel restarted: variables from earlier cells are gone, filesdef root() -> Path:- path = Path(os.environ.get("SANDBOX_WORKSPACES", "/workspaces"))- path.mkdir(mode=0o711, parents=True, exist_ok=True)- return path+ return Path(os.environ.get("SANDBOX_WORKSPACES", "/workspaces"))class BusyError(Exception):@@ -103,6 +101,8 @@ _starts: dict[tuple[str, str], threading.Lock] = {}def project_dir(project: str) -> Path:+ # Only a write creates the root: a sandbox beside a hosted provider has no workspaces.+ root().mkdir(mode=0o711, parents=True, exist_ok=True)path = root() / projectfor part in (path, path / "data", path / "conversations"):with contextlib.suppress(FileExistsError):diff --git a/tests/test_workspaces.py b/tests/test_workspaces.pyindex 5fe72ebc..3b04bc58 100644--- a/tests/test_workspaces.py+++ b/tests/test_workspaces.py@@ -3,9 +3,11 @@ import osimport sysimport pytest+from starlette.testclient import TestClientfrom overbae.services.workspaces import conformancefrom overbae.services.workspaces.native import NativeProvider+from sandbox import serverpytestmark = pytest.mark.covers("workspaces")@@ -54,3 +56,14 @@ def test_a_native_kernel_is_unprivileged_and_cannot_change_its_data(provider):assert result.ok and result.output == "'a,b\\n1,2\\n'\n", resultfinally:provider.stop("p1", "c1")+++def test_a_sandbox_without_workspaces_answers_reads_without_creating_them(tmp_path, monkeypatch):+ blocked = tmp_path / "file"+ blocked.write_text("")+ monkeypatch.setenv("SANDBOX_WORKSPACES", str(blocked / "workspaces"))+ monkeypatch.setenv("SANDBOX_TOKEN", "t")+ client = TestClient(server.app, headers={"Authorization": "Bearer t"})+ assert client.head("/v1/workspaces/p1/data/source.csv").status_code == 404+ assert client.get("/v1/workspaces/p1/kernels/c1/files/out.csv").status_code == 404+ assert client.delete("/v1/workspaces/p1").status_code == 204