Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio sandbox: remap the Windows spelling of /mnt/data-style paths (#16412)

Daniel Han66f1bedef0d6
diff --git a/studio/backend/core/inference/sandbox_site/sitecustomize.py b/studio/backend/core/inference/sandbox_site/sitecustomize.py
index 54e29155f71..28bfb029ffd 100644
--- a/studio/backend/core/inference/sandbox_site/sitecustomize.py
+++ b/studio/backend/core/inference/sandbox_site/sitecustomize.py
@@ -151,7 +151,14 @@ def _remap(path, notify = True):
return path
if not isinstance(text, str):
return path
+ # Windows renders Path("/mnt/data/x") as "\\mnt\\data\\x": compare both sides with forward slashes. A drive or UNC
+ # path still cannot match a rooted prefix like "/mnt/data".
+ windows = os.sep == "\\"
+ if windows:
+ text = text.replace("\\", "/")
for prefix in _PREFIXES + _CONDITIONAL_PREFIXES:
+ if windows:
+ prefix = prefix.replace("\\", "/")
# Heal only while the prefix directory is absent, so a real host mount is never shadowed.
if (text == prefix or text.startswith(prefix + "/")) and not os.path.exists(prefix):
return _map_onto_cwd(prefix, text, notify = notify)
diff --git a/studio/backend/tests/test_sandbox_sitecustomize.py b/studio/backend/tests/test_sandbox_sitecustomize.py
index b505209a2b5..737894af624 100644
--- a/studio/backend/tests/test_sandbox_sitecustomize.py
+++ b/studio/backend/tests/test_sandbox_sitecustomize.py
@@ -64,6 +64,64 @@ def test_always_remap_prefixes_map_into_cwd(monkeypatch, tmp_path):
assert mod._remap("relative.txt") == "relative.txt"
+def test_windows_backslash_spelling_of_a_prefix_maps_into_cwd(monkeypatch):
+ """On Windows str(Path("/mnt/data/x")) is "\\mnt\\data\\x"; the forward-slash prefix match alone missed it, so a
+ write fell back to the basename heal and the matching read failed (staging Windows leg, #16210)."""
+ import ntpath
+ import types
+
+ mod = _load_shim()
+ cwd = "C:\\sandbox\\work"
+ fake_os = types.SimpleNamespace(
+ **{name: getattr(os, name) for name in dir(os) if not name.startswith("__")}
+ )
+ fake_os.sep = "\\"
+ fake_os.path = types.SimpleNamespace(
+ **{name: getattr(ntpath, name) for name in dir(ntpath) if not name.startswith("__")}
+ )
+ fake_os.path.exists = lambda p: False
+ fake_os.getcwd = lambda: cwd
+ monkeypatch.setattr(mod, "os", fake_os)
+ assert mod._remap("\\mnt\\data\\out.txt") == ntpath.join(cwd, "out.txt")
+ assert mod._remap("/mnt/data/sub\\out.txt") == ntpath.join(cwd, "sub", "out.txt")
+ assert mod._remap("\\mnt\\data") == cwd
+ assert mod._remap("\\mnt\\data\\..\\..\\escape.txt") == ntpath.join(cwd, "escape.txt")
+ # A drive-qualified path is a real host location, never a code-interpreter convention.
+ assert mod._remap("D:\\mnt\\data\\out.txt") == "D:\\mnt\\data\\out.txt"
+ assert mod._remap("\\\\server\\share\\mnt\\data\\x") == "\\\\server\\share\\mnt\\data\\x"
+ assert mod._remap("data\\out.txt") == "data\\out.txt"
+
+
+ os.path.exists("/mnt/data"),
+ reason = "the host has a real /mnt/data, which the shim never shadows",
+)
+def test_a_pathlib_write_then_read_of_mnt_data_round_trips_in_a_child(tmp_path):
+ """End to end in a real interpreter with the shim on PYTHONPATH, on whatever OS runs the suite. Windows spells the
+ path with backslashes, which the prefix remap must still catch on the read as well as the write."""
+ import subprocess
+ import sys
+
+ code = (
+ "from pathlib import Path\n"
+ "p = Path('/mnt/data/round_trip.txt')\n"
+ "p.write_text('round trip')\n"
+ "print(p.read_text())\n"
+ )
+ env = {**os.environ, "PYTHONPATH": str(_SHIM.parent)}
+ proc = subprocess.run(
+ [sys.executable, "-c", code],
+ cwd = tmp_path,
+ env = env,
+ capture_output = True,
+ text = True,
+ timeout = 60,
+ )
+ assert proc.returncode == 0, proc.stderr
+ assert proc.stdout.strip() == "round trip"
+ assert (tmp_path / "round_trip.txt").read_text(encoding = "utf-8") == "round trip"
+
+
def test_prefix_remap_contains_parent_traversal_inside_cwd(monkeypatch, tmp_path):
# '..' components are dropped so the remap never escapes the per-conversation CWD.
mod = _load_shim()