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: allow full access for the installation owner (#12604)
Maheswar Kumardd3a704d519c
diff --git a/studio/backend/auth/policy.py b/studio/backend/auth/policy.pyindex fe0cc62d48b..6fe46b095de 100644--- a/studio/backend/auth/policy.py+++ b/studio/backend/auth/policy.py@@ -96,8 +96,9 @@ def installation_has_managed_accounts() -> bool:def full_access_permitted() -> bool:- """Unsandboxed tool modes: refused install-wide, owner included, if a managed account exists."""- return not installation_has_managed_accounts()+ """Only the installation owner may run tools outside the sandbox."""+ from utils.account_context import is_owner_context+ return is_owner_context()def _forbid(detail: str) -> HTTPException:diff --git a/studio/backend/models/auth.py b/studio/backend/models/auth.pyindex 7ac1827cfd3..5f027671557 100644--- a/studio/backend/models/auth.py+++ b/studio/backend/models/auth.py@@ -47,8 +47,8 @@ class AuthStatusResponse(BaseModel):full_access: bool = Field(True,description = (- "Whether the unsandboxed tool modes (Full access, bypass permissions) may be "- "offered. False whenever another account exists, active or not."+ "Legacy pre-login hint: false whenever another account exists, active or not. "+ "Signed-in clients offer Full access only to the installation owner."),)requires_password_change: bool = Field(diff --git a/studio/backend/routes/auth.py b/studio/backend/routes/auth.pyindex 11697e5e842..ba946959d70 100644--- a/studio/backend/routes/auth.py+++ b/studio/backend/routes/auth.py@@ -439,13 +439,14 @@ def auth_status() -> AuthStatusResponse:else True)# Only while the default password stands: that is what the deadline fires on.- from auth.policy import full_access_permitted, login_mode+ from auth.policy import installation_has_managed_accounts, login_modereturn AuthStatusResponse(initialized = storage.is_initialized(),default_username = storage.DEFAULT_ADMIN_USERNAME,login_mode = login_mode(),- full_access = full_access_permitted(),+ # Public pre-login hint for older clients; signed-in clients use the account role.+ full_access = not installation_has_managed_accounts(),requires_password_change = requires_change,bootstrap_deadline_seconds = (bootstrap_deadline_remaining_seconds() if requires_change else Nonediff --git a/studio/backend/state/tool_policy.py b/studio/backend/state/tool_policy.pyindex 18f475b9949..716f75d4736 100644--- a/studio/backend/state/tool_policy.py+++ b/studio/backend/state/tool_policy.py@@ -54,7 +54,7 @@ def require_tool_access(if not full_access_permitted():raise HTTPException(status_code = 400,- detail = "Full access is unavailable while more than one account exists.",+ detail = "Full access is only available to the installation owner.",)diff --git a/studio/backend/tests/multi_account/test_login_mode_transitions.py b/studio/backend/tests/multi_account/test_login_mode_transitions.pyindex a1223b91b9c..b83f9fb08ee 100644--- a/studio/backend/tests/multi_account/test_login_mode_transitions.py+++ b/studio/backend/tests/multi_account/test_login_mode_transitions.py@@ -34,10 +34,10 @@ def status(assert body["default_username"] == "unsloth"assert body["login_mode"] == ("multi" if count > 1 else "single")assert "alice" not in response.text and "bob" not in response.text- # Full access needs the install to itself: no managed account, active or not.+ # Preserve the public pre-login hint for older clients.if full_access is None:full_access = count <= 1- assert policy.full_access_permitted() == full_access+ assert (not policy.installation_has_managed_accounts()) == full_accessassert body["full_access"] == full_accessdiff --git a/studio/backend/tests/test_account_contract.py b/studio/backend/tests/test_account_contract.pyindex 60f07317f80..ec1aae33ef1 100644--- a/studio/backend/tests/test_account_contract.py+++ b/studio/backend/tests/test_account_contract.py@@ -210,7 +210,7 @@ def test_login_mode_follows_the_account_count(auth_db):assert policy.full_access_permitted() is Trueauth_db.create_initial_user("alice", "alice-password", secrets.token_urlsafe(32))assert policy.login_mode() == "multi"- assert policy.full_access_permitted() is False+ assert policy.full_access_permitted() is Trueauth_db.delete_user("alice")assert policy.login_mode() == "single"diff --git a/studio/backend/tests/test_account_credential_binding.py b/studio/backend/tests/test_account_credential_binding.pyindex 1641faabf85..ad53ac17ae4 100644--- a/studio/backend/tests/test_account_credential_binding.py+++ b/studio/backend/tests/test_account_credential_binding.py@@ -100,25 +100,25 @@ def test_owner_api_key_binds_the_owner(auth_db):assert bound == OWNER-def test_deactivated_account_keeps_full_access_closed_until_deleted(auth_db):- assert policy.full_access_permitted() is True+def test_deactivated_account_keeps_isolation_until_deleted(auth_db):+ assert policy.installation_has_managed_accounts() is Falsealice = _managed("alice")assert policy.login_mode() == "multi"- assert policy.full_access_permitted() is False+ assert policy.installation_has_managed_accounts() is Truestorage.set_account_active(alice["account_id"], False)assert policy.login_mode() == "single"assert policy.installation_is_multi_user() is Falseassert policy.managed_account_count() == 1- assert policy.full_access_permitted() is False+ assert policy.installation_has_managed_accounts() is Truestorage.set_account_active(alice["account_id"], True)- assert policy.full_access_permitted() is False+ assert policy.installation_has_managed_accounts() is Truestorage.delete_account(alice["account_id"], lambda account: None)assert policy.login_mode() == "single"assert policy.managed_account_count() == 0- assert policy.full_access_permitted() is True+ assert policy.installation_has_managed_accounts() is Falsedef test_status_reports_full_access_with_a_deactivated_account(auth_db):@@ -178,7 +178,7 @@ def test_unreadable_auth_db_keeps_the_host_closed(auth_db, monkeypatch):monkeypatch.setattr(storage, "account_counts", boom)policy.invalidate_account_cache()assert policy.login_mode() == "single"- assert policy.full_access_permitted() is False+ assert policy.installation_has_managed_accounts() is Truedef test_a_transient_auth_db_failure_is_not_cached(auth_db, monkeypatch):@@ -189,6 +189,6 @@ def test_a_transient_auth_db_failure_is_not_cached(auth_db, monkeypatch):monkeypatch.setattr(storage, "account_counts", boom)policy.invalidate_account_cache()- assert policy.full_access_permitted() is False+ assert policy.installation_has_managed_accounts() is Truemonkeypatch.setattr(storage, "account_counts", counts)- assert policy.full_access_permitted() is True+ assert policy.installation_has_managed_accounts() is Falsediff --git a/studio/backend/tests/test_account_integration_wiring.py b/studio/backend/tests/test_account_integration_wiring.pyindex 780ffe1d341..8869c860f41 100644--- a/studio/backend/tests/test_account_integration_wiring.py+++ b/studio/backend/tests/test_account_integration_wiring.py@@ -81,7 +81,7 @@ def _credentials(token):return authentication.HTTPAuthorizationCredentials(scheme = "Bearer", credentials = token)-_FULL_ACCESS = "Full access is unavailable while more than one account exists."+_FULL_ACCESS = "Full access is only available to the installation owner."_REQUESTS = {"/v1/chat/completions": {"model": "m", "messages": [{"role": "user", "content": "hi"}]},@@ -103,7 +103,7 @@ _REQUESTS = {{"disable_sandbox": True},],)[email protected]("account", [OWNER, ALICE], ids = ["owner", "alice"])[email protected]("account", [ALICE], ids = ["alice"])def test_full_access_is_refused_at_the_door_in_multi_mode(multi_user, monkeypatch, path, flags, account):@@ -118,8 +118,12 @@ def test_full_access_is_refused_at_the_door_in_multi_mode(@pytest.mark.parametrize("path", sorted(_REQUESTS))-def test_single_account_full_access_passes_the_door(monkeypatch, path):- monkeypatch.setattr(policy, "installation_is_multi_user", lambda: False)[email protected]("multi", [False, True])+ "flags", [{"permission_mode": "full"}, {"bypass_permissions": True}, {"disable_sandbox": True}]+)+def test_owner_full_access_passes_the_door(monkeypatch, path, multi, flags):+ monkeypatch.setattr(policy, "installation_is_multi_user", lambda: multi)def backend():raise HTTPException(status_code = 503, detail = "no backend in this test")@@ -127,8 +131,9 @@ def test_single_account_full_access_passes_the_door(monkeypatch, path):monkeypatch.setattr(inference, "get_llama_cpp_backend", backend)monkeypatch.setattr(inference, "produce_openai_chat_completions", lambda *a, **k: backend())with _client_for(OWNER) as client:- response = client.post(path, json = {**_REQUESTS[path], "bypass_permissions": True})- assert response.status_code != 400 or response.json().get("detail") != _FULL_ACCESS+ response = client.post(path, json = {**_REQUESTS[path], **flags})+ assert response.status_code == 503, response.text+ assert response.json()["detail"] == "no backend in this test"def test_admission_runs_after_the_docstring_and_reads_every_flag():diff --git a/studio/backend/tests/test_account_policy_states.py b/studio/backend/tests/test_account_policy_states.pyindex 64da75f6afb..cef8cb0b63e 100644--- a/studio/backend/tests/test_account_policy_states.py+++ b/studio/backend/tests/test_account_policy_states.py@@ -1,7 +1,7 @@# SPDX-License-Identifier: AGPL-3.0-only# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0-"""``login_mode`` / ``installation_is_multi_user`` follow the ACTIVE count; ``installation_has_managed_accounts`` and the full-access gate follow whether any managed account exists at all."""+"""``login_mode`` / ``installation_is_multi_user`` follow the ACTIVE count; ``installation_has_managed_accounts`` follows whether any managed account exists; full access follows the acting account."""import secrets@@ -37,13 +37,13 @@ def test_owner_only(auth_db):def test_owner_plus_one_active_managed_account(auth_db):storage.issue_account_setup_code(username = "alice")- assert _state() == ("multi", True, True, False)+ assert _state() == ("multi", True, True, True)def test_owner_plus_one_deactivated_managed_account(auth_db):account = storage.issue_account_setup_code(username = "alice")["account"]storage.set_account_active(account["account_id"], False)- assert _state() == ("single", False, True, False)+ assert _state() == ("single", False, True, True)def test_an_unreadable_auth_database(auth_db, monkeypatch):@@ -51,7 +51,7 @@ def test_an_unreadable_auth_database(auth_db, monkeypatch):raise OSError("auth.db unreadable")monkeypatch.setattr(storage, "account_counts", boom)- assert _state() == ("single", False, True, False)+ assert _state() == ("single", False, True, True)def test_a_count_read_failure_keeps_a_bound_managed_account_isolated(auth_db, monkeypatch):@@ -129,3 +129,27 @@ def test_deactivating_the_last_account_does_not_hand_its_download_to_the_owner(legacy = "legacy-org/model::"registry.claim(legacy, "http", repo_type = "model", repo_id = "legacy-org/model")assert run_as(OWNER, download_lifecycle.download_belongs_to_account, registry, legacy) is True++[email protected]("active", [True, False])+def test_full_access_follows_the_account_role(auth_db, active):+ from state.tool_policy import require_tool_access+ from fastapi import HTTPException+ from utils.account_context import OWNER, AccountContext, run_as++ record = storage.issue_account_setup_code(username = "alice")["account"]+ alice = AccountContext(record["account_id"], "alice")+ storage.set_account_active(record["account_id"], active)+ assert run_as(OWNER, policy.full_access_permitted) is True+ assert run_as(alice, policy.full_access_permitted) is False+ for flags in (+ {"permission_mode": "full"},+ {"bypass_permissions": True},+ {"disable_sandbox": True},+ ):+ run_as(OWNER, require_tool_access, **flags)+ with pytest.raises(HTTPException, match = "installation owner"):+ run_as(alice, require_tool_access, **flags)++ storage.delete_account(record["account_id"], lambda account: None)+ assert run_as(alice, policy.full_access_permitted) is Falsediff --git a/studio/backend/tests/test_account_tool_isolation.py b/studio/backend/tests/test_account_tool_isolation.pyindex da1a4772e2e..04506674bf3 100644--- a/studio/backend/tests/test_account_tool_isolation.py+++ b/studio/backend/tests/test_account_tool_isolation.py@@ -159,12 +159,15 @@ def test_edit_file_cannot_read_or_write_foreign_sandbox(other, kind):@pytest.mark.parametrize("flags", [{"permission_mode": "full"}, {"bypass_permissions": True}, {"disable_sandbox": True}])-def test_full_access_admission_refuses_every_account_in_multi_mode(account, flags):+def test_full_access_admission_follows_the_account_role(account, flags):+ if account.is_owner:+ run_as(account, tool_policy.require_tool_access, **flags)+ returnwith pytest.raises(HTTPException) as exc:run_as(account, tool_policy.require_tool_access, **flags)assert exc.value.status_code == 400assert "full access" in exc.value.detail.lower()- assert "more than one account exists" in exc.value.detail+ assert "installation owner" in exc.value.detail@pytest.mark.parametrize(@@ -194,7 +197,7 @@ def test_sandboxed_admission_never_queries_installation_policy(monkeypatch):def test_direct_tool_bypass_is_rejected_before_dispatch(monkeypatch):monkeypatch.setattr(tools, "_bash_exec", lambda *a, **kw: pytest.fail("tool ran"))with pytest.raises(HTTPException) as exc:- tools.execute_tool("terminal", {"command": "pwd"}, disable_sandbox = True)+ run_as(ALICE, tools.execute_tool, "terminal", {"command": "pwd"}, disable_sandbox = True)assert exc.value.status_code == 400@@ -401,7 +404,7 @@ def test_closing_mcp_sessions_only_closes_acting_account(monkeypatch):)[email protected]("account", ACCOUNTS)[email protected]("account", (ALICE, BOB))@pytest.mark.parametrize("loop_name", ["gguf", "safetensors", "studio", "codex"])def test_every_tool_loop_refuses_full_access_before_model_or_tool_dispatch(account, loop_name):def check():@@ -709,3 +712,26 @@ def test_sandbox_recovery_runs_once_for_each_account(isolated, monkeypatch):assert not worker.is_alive()assert run_as(account, isolated) is Noneassert seen == [ALICE.account_id, BOB.account_id]++[email protected]("account", ACCOUNTS)+def test_only_owner_full_access_can_edit_outside_the_sandbox(account, tmp_path):+ target = tmp_path / "outside-sandbox.txt"+ target.write_text("original", encoding = "utf-8")++ def edit():+ return run_as(+ account,+ tools.execute_tool,+ "edit_file",+ {"path": str(target), "edits": [{"old_string": "original", "new_string": "updated"}]},+ disable_sandbox = True,+ )++ if account.is_owner:+ edit()+ assert target.read_text(encoding = "utf-8") == "updated"+ else:+ with pytest.raises(HTTPException, match = "installation owner"):+ edit()+ assert target.read_text(encoding = "utf-8") == "original"diff --git a/studio/frontend/src/features/auth/account-session.ts b/studio/frontend/src/features/auth/account-session.tsindex 0c2394ce5f9..63f77357f58 100644--- a/studio/frontend/src/features/auth/account-session.ts+++ b/studio/frontend/src/features/auth/account-session.ts@@ -4,7 +4,6 @@import { useEffect, useSyncExternalStore } from "react";import {ensureLoginMode,- getFullAccessAllowed,getLoginMode,subscribeLoginMode,} from "./login-client";@@ -67,13 +66,7 @@ export function useLoginMode() {useEffect(ensureLoginMode, []);return mode;}-/** Whether Full access may be offered; false whenever another account exists, active or not. */+/** The server enforces the same owner-only rule for unsandboxed tool calls. */export function useFullAccessAllowed(): boolean {- const allowed = useSyncExternalStore(- subscribeLoginMode,- getFullAccessAllowed,- () => true,- );- useEffect(ensureLoginMode, []);- return allowed;+ return useIsAccountOwner();}diff --git a/studio/frontend/tests/account-permissions.test.ts b/studio/frontend/tests/account-permissions.test.tsindex 50e0b33e9e8..6547f780d27 100644--- a/studio/frontend/tests/account-permissions.test.ts+++ b/studio/frontend/tests/account-permissions.test.ts@@ -9,7 +9,20 @@ import {type StubElement,} from "./helpers/module-stubs.ts";-function permissionUi(loginMode: string, permissionMode: string) {+function permissionUi(owner: boolean, permissionMode: string, loginMode = "multi") {+ const accountSession = loadWithStubs<{+ useFullAccessAllowed: () => boolean;+ }>(new URL("../src/features/auth/account-session.ts", import.meta.url), {+ react: { useSyncExternalStore: (_subscribe: unknown, snapshot: () => boolean) => snapshot() },+ "./login-client": {+ getFullAccessAllowed: () => loginMode !== "multi",+ },+ "./session": {+ getAuthToken: () => `e30.${Buffer.from(JSON.stringify({+ sub: owner ? "unsloth" : "alice", role: owner ? "owner" : "user",+ })).toString("base64url")}.sig`,+ },+ });const changes: string[] = [];const state = {permissionMode,@@ -44,9 +57,7 @@ function permissionUi(loginMode: string, permissionMode: string) {selector({ openDialog: () => {} }),},"@/i18n": { useT: () => (key: string) => key },- "@/features/auth/account-session": {- useFullAccessAllowed: () => loginMode !== "multi",- },+ "@/features/auth/account-session": accountSession,"@/components/ui/alert-dialog": { AlertDialog: "AlertDialog" },"@/components/ui/button": { Button: "Button" },"@/components/ui/dropdown-menu": { DropdownMenuItem: "DropdownMenuItem" },@@ -66,26 +77,28 @@ function permissionUi(loginMode: string, permissionMode: string) {return { component, changes };}-for (const mode of ["single", "multi"]) {- test(`${mode} permission menu enforces installation full-access policy`, () => {- const ui = permissionUi(mode, "full");- const menu = ui.component.PermissionModeMenuItems({- onRequestFullAccess() {},+for (const loginMode of ["single", "multi"]) {+ for (const owner of [true, false]) {+ test(`${loginMode} permission menu allows full access only for the owner (${owner})`, () => {+ const ui = permissionUi(owner, "full", loginMode);+ const menu = ui.component.PermissionModeMenuItems({+ onRequestFullAccess() {},+ });+ const rows = menu.props.children as StubElement[];+ assert.equal(rows.length, owner ? 4 : 3);+ assert.deepEqual(ui.changes, owner ? [] : ["auto"]);+ const dialog = ui.component.FullAccessConfirmDialog({+ open: true,+ onOpenChange() {},+ });+ assert.equal(dialog === null, !owner);});- const rows = menu.props.children as StubElement[];- assert.equal(rows.length, mode === "multi" ? 3 : 4);- assert.deepEqual(ui.changes, mode === "multi" ? ["auto"] : []);- const dialog = ui.component.FullAccessConfirmDialog({- open: true,- onOpenChange() {},- });- assert.equal(dialog === null, mode === "multi");- });+ }}test("multi-user policy leaves non-full preferences untouched", () => {for (const mode of ["ask", "auto", "off"]) {- const ui = permissionUi("multi", mode);+ const ui = permissionUi(false, mode);ui.component.PermissionModeMenuItems({onRequestFullAccess() {assert.fail("Full access must be unavailable");diff --git a/studio/frontend/tests/login-account-modes.test.ts b/studio/frontend/tests/login-account-modes.test.tsindex 3cfd00a4d21..2e73d408e5b 100644--- a/studio/frontend/tests/login-account-modes.test.ts+++ b/studio/frontend/tests/login-account-modes.test.ts@@ -475,7 +475,7 @@ test("multi-user policy survives document reloads and revalidates only multi-useassert.equal(requests, 1);});-test("creating an account hides full access in peer tabs without a status request", (t) => {+test("creating an account restricts the legacy full-access hint in peer tabs", (t) => {environment(t);globalThis.fetch = async () => {assert.fail("storage synchronization must not fetch status");@@ -517,7 +517,7 @@ test("creating an account hides full access in peer tabs without a status requesassert.equal(handlers.size, 0);});-test("a deactivated account keeps full access hidden while the form is back in single mode", async (t) => {+test("a deactivated account keeps the legacy hint restricted in single mode", async (t) => {environment(t);window.localStorage.setItem("unsloth_chat_permission_mode", "full");const api = client();@@ -559,7 +559,7 @@ test("a deactivated account keeps full access hidden while the form is back in sassert.equal(api.getFullAccessAllowed(), false);});-test("a deactivated account hides full access in peer tabs without changing the login form", (t) => {+test("a deactivated account restricts the legacy hint in peer tabs without changing the login form", (t) => {environment(t);const handlers = new Set<(event: Partial<StorageEvent>) => void>();window.addEventListener = ((