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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: split the Full access rewrite claims per API, and drop the local-desktop promise (#8605)
Daniel Han19bad46ed52a
diff --git a/studio/backend/core/inference/tools.py b/studio/backend/core/inference/tools.pyindex 2afaa4173b9..a73691d6741 100644--- a/studio/backend/core/inference/tools.py+++ b/studio/backend/core/inference/tools.py@@ -8964,6 +8964,14 @@ _FULL_ACCESS_SUBSTITUTIONS = (# user's own machine" is narrowed at the same time: --secure and -H 0.0.0.0# are documented remote modes (README), and the tools run on the host serving# Studio, which is then not the device the user is looking at.+ # _TERMINAL_SHELL_NOTE is carried through unchanged except here: its Git Bash+ # branch promises a detached program's window appears on the user's desktop,+ # which only holds while Studio is local.+ (+ "opens a window on the user's desktop.",+ "opens a window on that machine's desktop, which the user sees only if "+ "they are sitting at it.",+ ),(" You are on Windows, and this runs on the user's own machine."," You are on Windows, and this runs wherever Unsloth Studio is running, "@@ -8991,8 +8999,22 @@ _FULL_ACCESS_SUBSTITUTIONS = (# prefix is special only while absent, which is why# the clause names one inside a conditional and# never categorically-# python, unpatched API -> only open/io.open/os.open and the mkdir family are-# wrapped: os.rename and os.symlink raise, while+# API coverage differs per rewrite -> _makedirs calls _remap only, so the+# generic fallback is open/io.open/os.open alone and+# os.makedirs under a missing parent OUTSIDE the+# convention prefixes targets the REAL host path.+# Inside them _remap still rewrites, measured:+# makedirs("/mnt/data/reports") created ./reports and+# raised nothing, so the clause has to name the prefixes+# rather than say "not rewritten at all" -- a model told+# otherwise reports the host path for a directory that+# is in its working directory.+# An attempt, not an outcome: measured+# under this shim, makedirs into a mode-500 directory+# raised PermissionError and created nothing, neither+# on the host nor in the workdir, so the clause must+# not promise creation any more than it promises a+# prefix is absent. os.rename and os.symlink raise, while# shutil.copy writes the rewritten file through open# and then raises in copymode# terminal -> the shell's own rules, except for Python it@@ -9007,11 +9029,15 @@ _FULL_ACCESS_CLAUSE = {"already sitting there; under any other missing directory only the base ""name is kept, and the write fails outright if that name is taken by an ""unrelated file, though rewriting the same absolute path just replaces "- "what your own earlier call left there. Both reach only open() and the "- "mkdir calls, so os.rename, os.symlink and the like are never rewritten "- "and simply fail, and a helper such as shutil.copy can write the "- "rewritten file and still raise on a later step. Report where a file "- "actually landed rather than the path you asked for."+ "what your own earlier call left there. The convention rewrite covers "+ "open() and the mkdir calls; the other covers open() alone, so "+ "os.makedirs under a missing parent outside those prefixes is not "+ "rewritten and attempts the real host path, which then succeeds or fails "+ "on the filesystem's own permissions. "+ "Neither touches os.rename or os.symlink, which simply fail, and a helper "+ "such as shutil.copy can write the rewritten file and still raise on a "+ "later step. Report where a file actually landed rather than the path you "+ "asked for."),"terminal": (" The code sandbox is disabled, so absolute paths do resolve as the shell "diff --git a/studio/backend/tests/test_full_access_tool_prompt.py b/studio/backend/tests/test_full_access_tool_prompt.pyindex b315e72b7ea..acf04ba2422 100644--- a/studio/backend/tests/test_full_access_tool_prompt.py+++ b/studio/backend/tests/test_full_access_tool_prompt.py@@ -18,6 +18,8 @@ other mode keeps the sandboxed wording verbatim."""import asyncio+import json+import osimport sysimport pytest@@ -141,7 +143,16 @@ def test_the_substitutions_land_on_every_platform(monkeypatch, platform, tool_na# Only open/io.open/os.open and the mkdir family are wrapped. Measured:# os.rename and os.symlink raise, and shutil.copy writes the rewritten# file through open and then raises in copymode.- assert "reach only open() and the mkdir calls" in full+ # Measured: os.makedirs under a missing parent OUTSIDE the convention+ # prefixes targets the REAL host path, because _makedirs calls _remap only+ # and never the generic fallback, so the two rewrites do NOT cover the same+ # APIs. Inside a prefix _remap still rewrites, so the clause is scoped:+ # makedirs("/mnt/data/reports") with no /mnt/data created ./reports.+ assert "The convention rewrite covers open() and the mkdir calls" in full+ assert "the other covers open() alone" in full+ assert "os.makedirs under a missing parent outside those prefixes" in full+ assert "is not rewritten and attempts the real host path" in full+ assert "missing absolute parent is not rewritten at all" not in fullassert "shutil.copy can write the rewritten file and still raise" in fullelse:assert "absolute paths do resolve as the shell resolves them" in full@@ -171,6 +182,22 @@ def test_python_full_access_description_still_omits_the_shell():assert "shell" not in _desc(PYTHON_TOOL_FULL_ACCESS).lower()+def test_full_access_drops_the_local_desktop_promise(monkeypatch):+ """The Git Bash branch of the shell note says a detached program opens a+ window on the user's desktop, which only holds while Studio is local. The+ Full access text now says it may be remote or containerized, so the two+ would contradict each other."""+ monkeypatch.setattr(sys, "platform", "win32")+ monkeypatch.setattr(tools, "_windows_bash", lambda: r"C:\bash.exe")+ note = tools._build_terminal_shell_note()+ assert "opens a window on the user's desktop" in note+ full = tools._to_full_access("X." + note, "terminal")+ assert "opens a window on the user's desktop" not in full+ assert "on that machine's desktop" in full+ # The shell-selection guidance itself has to survive.+ assert "The shell is bash (Git for Windows)" in full++def test_terminal_full_access_keeps_the_shell_note():"""The shell note is platform-derived and applies in either mode; droppingit on Windows brings back the cmd/bash confusion it exists to prevent."""@@ -405,3 +432,125 @@ def test_count_request_selection_matches_the_completion():))assert _desc(_named(counted, "python")) == _desc(PYTHON_TOOL_FULL_ACCESS)+++def _sandbox_site_dir():+ from pathlib import Path+ return Path(tools.__file__).resolve().parent / "sandbox_site"+++# hasattr, not the win32 marker above: a marker's argument is evaluated when the decorator+# is applied, so os.geteuid() runs at import on a platform that has no geteuid and takes the+# whole module down at collection, every test in it, not just this one.[email protected](sys.platform == "win32", reason = "POSIX directory modes")+ hasattr(os, "geteuid") and os.geteuid() == 0,+ reason = "root ignores a mode-500 directory",+)+def test_the_mkdir_clause_promises_an_attempt_not_a_created_directory(tmp_path):+ """The unrewritten mkdir path is an attempt, and the clause may not promise more.++ Full access keeps _SANDBOX_SITE_DIR on PYTHONPATH, so ``os.makedirs`` is+ wrapped -- but ``_makedirs`` calls ``_remap`` alone, so outside a convention+ prefix nothing is rewritten and the real host path is what the syscall gets.+ A process that cannot create that path (a non-root write under a root-owned+ directory, a read-only mount) raises instead, creating nothing anywhere. The+ subprocess below is that measurement, not an assumption about os.makedirs:+ the same shim the model runs under, a mode-500 parent, and a check that+ neither the host path nor a workdir fallback appeared.++ The clause is held to the standard the rest of this comment block already+ keeps -- see the convention-prefix branch, which names /mnt/data only inside+ a conditional and never categorically.+ """+ import subprocess++ workdir = tmp_path / "work"+ readonly = tmp_path / "readonly"+ workdir.mkdir()+ readonly.mkdir()+ readonly.chmod(0o500)+ try:+ probe = subprocess.run(+ [+ sys.executable,+ "-c",+ "import json, os, sys\n"+ "target = sys.argv[1] + '/missing/child'\n"+ "try:\n"+ " os.makedirs(target)\n"+ " outcome = 'created'\n"+ "except OSError as exc:\n"+ " outcome = type(exc).__name__\n"+ "print(json.dumps({'outcome': outcome, 'host': os.path.exists(target),\n"+ " 'workdir': sorted(os.listdir('.'))}))\n",+ str(readonly),+ ],+ cwd = workdir,+ env = {**os.environ, "PYTHONPATH": str(_sandbox_site_dir())},+ capture_output = True,+ text = True,+ timeout = 120,+ )+ finally:+ readonly.chmod(0o700)+ assert probe.returncode == 0, probe.stderr+ measured = json.loads(probe.stdout.strip().splitlines()[-1])+ assert measured["outcome"] == "PermissionError", measured+ assert measured["host"] is False, "nothing was created on the host"+ assert measured["workdir"] == [], "and nothing fell back into the working directory"++ full = tools._to_full_access(+ "Execute Python code in a sandbox and return stdout/stderr."+ + tools._build_sandbox_paths_note(),+ "python",+ )+ assert (+ "really does create it" not in full+ ), "the clause promises a directory the filesystem may refuse to create"+ assert "outside those prefixes is not rewritten" in full+ assert "attempts the real host path" in full++[email protected](sys.platform == "win32", reason = "POSIX directory modes")[email protected](os.path.exists("/mnt/data"), reason = "a real mount is never shadowed")+def test_the_mkdir_clause_is_scoped_to_parents_outside_the_convention_prefixes(tmp_path):+ """Inside a convention prefix, makedirs IS rewritten, so the clause cannot be flat.++ ``_makedirs`` calls ``_remap``, and ``_remap``'s convention branch keeps the+ suffix under the working directory before it reaches the generic fallback. So+ ``/mnt/data/reports`` has a missing absolute parent and still lands in the+ workdir. A clause saying makedirs under a missing absolute parent is not+ rewritten at all would have the model report a host path for a directory+ sitting in its working directory, which is the one thing the closing sentence+ asks it not to do.+ """+ import subprocess++ workdir = tmp_path / "work"+ workdir.mkdir()+ probe = subprocess.run(+ [+ sys.executable,+ "-c",+ "import json, os\n"+ "target = '/mnt/data/reports'\n"+ "try:\n"+ " os.makedirs(target)\n"+ " outcome = 'created'\n"+ "except OSError as exc:\n"+ " outcome = type(exc).__name__\n"+ "print(json.dumps({'outcome': outcome, 'host': os.path.exists(target),\n"+ " 'workdir': sorted(os.listdir('.'))}))\n",+ ],+ cwd = workdir,+ env = {**os.environ, "PYTHONPATH": str(_sandbox_site_dir())},+ capture_output = True,+ text = True,+ timeout = 120,+ )+ assert probe.returncode == 0, probe.stderr+ measured = json.loads(probe.stdout.strip().splitlines()[-1])+ assert measured["outcome"] == "created", measured+ assert measured["host"] is False, "the absent prefix is not created on the host"+ assert measured["workdir"] == ["reports"], measured