Skip to content

Unsloth Studio: let browser_navigate open files the model wrote in its tool workspace - #18062

Merged
danielhanchen merged 13 commits into
unslothai:mainfrom
LeoBorcherding:studio/browser-open-workspace-files
Nov 19, 2026
Merged

danielhanchen merged 13 commits into
unslothai:mainfrom
LeoBorcherding:studio/browser-open-workspace-files

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

The problem

Ask Unsloth Studio to "make a single html file that draws something on a canvas and show it to me in the browser", and the model writes mandelbrot.html with python or terminal, then calls browser_navigate with mandelbrot.html, ./x.html or file:///.../x.html. Every one of those fails before the panel sees it: a bare name is read as a host ("Failed to resolve host"), a file:// URL is refused ("only http/https URLs are allowed", web_access_policy.py#L128-L129), and ./x.html gives "invalid hostname or port". The tool works fine on real http(s) URLs. It had no way to show a file the model just made.

Serving the workspace on a loopback URL wouldn't fix it: the panel refuses every loopback origin the user didn't type into the tab's address bar (executor.ts navigateTo, L1066-L1076), so the error would only move from the backend to the panel.

The fix

  • browser_navigate recognizes a workspace file by syntax alone: a bare page.html, a relative or absolute path, a file:// URL (including file:///C:/... on Windows), or a folder path such as out/page.html. A bare name the workspace has but that reads like a site (run.py, notes.md) is answered with "open it as ./run.py", so the approval check and the open always agree. It resolves the path in the same per-chat workspace python and terminal run in (_get_workdir(session_id)) and sends the panel an open_file action carrying the bytes (2 MB cap).
  • The panel opens it as a file tab, the same sandboxed preview a page made in chat gets, so browser_snapshot, browser_read_file and browser_edit_file work on it. Reopening the same path refreshes that tab.
  • A path outside the workspace, a symlink out of it, or a missing file is refused with what to do instead, e.g. "x is outside the workspace ... Write or copy the file there first, then open it by its name, or give a full http(s) address."
  • The URL path is unchanged: website policy, SSRF checks and the refusal of Unsloth's own ports still apply to every web address. example.com/page.html, localhost:3000/x.html and example.py are still sites.
  • The tool description now says it opens workspace files, and the status badge names the file.

Approval

Opening a workspace file hands its bytes to the model, so it now asks like any other sensitive read: in Ask and Auto (the default) the call stops on the usual approval card; Off and Full Access do not ask, as for every other tool there. Web addresses are unchanged. The read is race-safe: it walks from a held workspace directory without following links and checks the opened file is the one that was approved, as view_image does, so a file or folder swapped for a link after the checks is refused. Probing a name never creates a sandbox for a chat that only browses.

Tests

  • studio/backend/tests/test_browser_agent.py: workspace names, paths and file URLs open; outside paths, .., ~, symlinks out and missing files are refused with guidance; sites with file-like paths stay sites; a malformed file://[ is refused, not raised; the action carries this chat's file; status badge. 90 passed.

  • studio/frontend/tests/browser-agent-files.test.ts: open_file opens a file tab and reads its preview; a reopen (same length too) shows the new bytes; an off-screen chat is refused before any tab opens. 13 passed.

  • test_opening_a_workspace_file_asks_wherever_a_sensitive_read_asks: 4 permission modes x 11 targets; test_the_approval_check_and_the_open_agree_on_every_target; race tests swap the file and a parent for links after the checks.

  • Staging: browser agent tests pass on ubuntu-latest, windows-latest and macos-15.

Before/after in Studio

A scripted OpenAI-compatible model, added as a Custom connection, calls browser_navigate {"url": "draw.html"} on a file seeded in the chat's workspace; permission mode Auto. Before, the call runs unasked and its result is Failed to resolve host (the scripted model's closing line is fixed text on both sides). After, it stops on an approval card; after Allow the browser panel opens the page.

First stop: before runs unasked, after asks

After Allow: the panel shows draw.html from the workspace

Before/after on AMD NPU models

Running on the AMD DevLab Strix Halo runner; results and screenshots will be added here.

Not covered

The real panel in Unsloth Desktop (native views) wasn't driven.

A model that writes page.html with python and then calls browser_navigate
with page.html, ./page.html or file:///.../page.html got a host lookup or
scheme error. A path inside this chat's tool workspace now opens as a file
tab in the browser panel (the same sandboxed preview a chat-made page gets);
a path outside it is refused with what to do instead.
danielhanchen added a commit to Etherll/unsloth that referenced this pull request Nov 18, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-19T08:16:36.500674Z
We couldn’t complete this review. Comment @codex review to try again.
0452712 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1150a443b6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +673 to +674
with open(full, "rb") as handle:
data = handle.read(_MAX_WORKSPACE_FILE_BYTES + 1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Open workspace files through race-safe file descriptors

A concurrent workspace writer can replace the checked file or a parent directory with a symlink after the containment checks but before this open. The server then reads the target and sends it in open_file.data, exposing server-readable files outside the chat workspace. Replacing draw.html with an outside-file symlink between getsize and open reproduces the leak. Open relative to a held workspace directory descriptor with no-follow semantics and validate the opened descriptor, as view_image already does.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in db56c81: the read now walks from a held workspace descriptor with O_NOFOLLOW and checks the opened inode against the resolved path, as view_image does; tests swap the file and a parent for links after the checks.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 18, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: db56c81993

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added a commit that referenced this pull request Nov 18, 2026
…ad (#18315)

## Translate: keep the stable gutter without a :has() over the chat
thread

The long-thread composer gate,
`tests/studio/playwright_long_thread_gate.py`, fails on `main` since
#18293. It fails on every PR that runs it, for example #18062 and
#18108, across `Frontend build + bundle sanity`, `Frontend unit tests
(Windows)` and `Composer`:

```
FAIL: :has() matching costs 6.7 ms per keystroke at 200 turns, budget 5.0 ms (1.3x over)
  studio/frontend/src/index.css:5473 (exact text match)
    main:has(.translate-page)
```

### Cause

#18293 added this rule so a classic scrollbar does not narrow the
Translate panes:

```css
main:has(.translate-page) { scrollbar-gutter: stable; }
```

The `<main>` it matches is the layout's scroll container, and on the
chat page that element holds the whole thread. An unanchored `:has()`
there makes Chromium re-walk every descendant on each keystroke. The
gate measures exactly that cost, and it grows with the chat.

### Fix

The intent is unchanged: while Translate is open, its layout `<main>`
keeps a stable gutter. Only the way that element is selected changes.

- `translate-page.tsx`: a layout effect marks the layout `<main>` that
holds `.translate-page` with `data-translate-page` while the page is
mounted, and removes it on unmount. The page's own root is also a
`<main>`, so the effect starts from its parent.
- `index.css`: `main:has(.translate-page)` becomes
`main[data-translate-page]`.

An attribute selector costs nothing per keystroke, and the Translate
page renders the same.

### Verification

**Long-thread gate, run locally on the same host:**

| | `:has()` at 40 turns | `:has()` at 200 turns | Selector matching
growth | Gate |
|---|---|---|---|---|
| `main` | 0.76 ms/key | 3.86 ms/key | 2.11x for 5x the turns (limit
2.0x) | FAIL |
| this PR | 0.06 ms/key | 0.09 ms/key | 0.38 to 0.45 ms/key | PASS |

**Other checks:**

- `tests/translate-page.test.ts`: 27 passed.
- `npm run typecheck`: no errors.


### Screenshots

Translate page at 1366x768, before (`main`) and after (this PR). Each
side was built from its own isolated Studio install. Both render the
same page, and on both the layout `<main>` reports `scrollbar-gutter:
stable`. The page width is 1076 px on both sides.

![Translate page before and after: identical, stable gutter on
both](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/18315/pr18315_before_after_q-ecdc78103391.png)
@danielhanchen
danielhanchen marked this pull request as ready for review November 19, 2026 08:16
@danielhanchen
danielhanchen merged commit e392833 into unslothai:main Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants