Skip to content

Add SRT-backed isolation for Studio Python and Terminal tools - #10441

Closed
Etherll wants to merge 32 commits into
unslothai:mainfrom
Etherll:codex/studio-srt-replacement-20260907
Closed

Etherll wants to merge 32 commits into
unslothai:mainfrom
Etherll:codex/studio-srt-replacement-20260907

Conversation

@Etherll

@Etherll Etherll commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Run Studio's Python and Terminal tools through a pinned SRT helper by default. Required mode refuses execution when the runtime is missing or its probe fails; users can explicitly
consent to Limited mode or separately confirm Full access.

BREAKING CHANGE

Hosts that previously ran tools with software safeguards alone may now refuse Python and Terminal calls.

Rerun Studio setup to install the helper and check Sandbox details for platform prerequisites. When isolation is unavailable, users can accept the Limited-mode warning and retry

Motivation

  • Add the SRT adapter, live capability probes, launch verification and process cleanup under studio/backend/core/inference/.
  • Add Linux network denial and optional HTTPS allowlists through private proxy sockets.
  • Add capability details, session-bound Limited consent and backend-owned execution labels to the chat UI.
  • Revalidate permissions immediately before dispatch and authentication retries.
  • Preserve completion records when streaming output is batched or capped.
  • Install the helper with Studio's selected environment and package its lockfile, reviewed patches and integrity manifest.
  • Add regression tests, native test fixtures and a tool-isolation CI workflow.

Dependencies: add @anthropic-ai/sandbox-runtime pinned to 0.0.75; the helper requires Node 20.11 or newer. pyproject.toml changes package contents, not Python dependencies.

How to test

On a host without working isolation:

  1. Load a model and confirm ordinary chat works with Code disabled.
  2. Enable Code and send a Python request. Confirm "Sandbox unavailable" and the "Use Limited mode?" warning.
  3. Cancel and confirm nothing executes.
  4. Accept Limited, then click Retry. Check Python and Terminal output and their "Limited · no OS isolation" labels.
  5. Select Require sandbox or reload, then confirm tool requests are blocked again.

Etherll and others added 18 commits September 7, 2026 17:19
…260907' into codex/studio-srt-replacement-20260907

# Conflicts:
#	studio/backend/tests/test_srt_native_tools.py
…260907' into codex/studio-srt-replacement-20260907
@danielhanchen

Copy link
Copy Markdown
Member

This makes Required isolation the default for Python and Terminal tool calls, so any host where the pinned SRT runtime is missing or fails its probe now refuses to run tools that work today; could you confirm what a user on such a host sees before I review? It also bundles the network proxy, the Windows installer provisioning and the Detours adapter into one branch, so splitting the platform backends out from the shared launch contract in os_sandbox.py would make this reviewable.

@Etherll

Etherll commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

This makes Required isolation the default for Python and Terminal tool calls, so any host where the pinned SRT runtime is missing or fails its probe now refuses to run tools that work today; could you confirm what a user on such a host sees before I review? It also bundles the network proxy, the Windows installer provisioning and the Detours adapter into one branch, so splitting the platform backends out from the shared launch contract in os_sandbox.py would make this reviewable.

Yes, tools that worked before will be blocked on those hosts unless the user explicitly chooses Limited mode. I tested this on a Colab T4 at 030c87c:

  1. The menu shows "Sandbox unavailable", and sending a Python or Terminal request opens "Use Limited mode?" with a warning about access to files, credentials, and the network.

  2. Cancel leaves an error and a Retry button without running anything; accepting Limited still requires clicking Retry. Both tools then worked, with their results labelled
    "Limited · no OS isolation".

  3. Switching back to Required or reloading blocks tools again. Ordinary chat still works.

Sandbox unavailable :

01-sandbox-unavailable

Probe details :

02-sandbox-details

Limited-mode warning

04-required-block-dialog

After Cancel

05-cancel-remains-blocked

Successful Python execution (colab-10441-030c87cfb/)

06-limited-python-output

Successful Terminal execution

07-limited-terminal-output

Etherll and others added 4 commits September 8, 2026 08:03
The seven failing checks came from three stale assertions, not from the
isolation work:

- pre-commit's prettier wrapped useSandboxImage(pythonToolImagePath(...))
  across lines, and two guards matched that call as literal source text.
  Both now match it whitespace-tolerantly, the way the authFetch assertion
  beside one of them already did, so the formatter cannot break them again.
- playwright_chat_ui.py still expected the old Full-access copy ("the code
  sandbox") and the old button label ("I understand"), both reworded here.
  That one file failed the Linux, macOS and Windows chat lanes.

Then the case this change is really about. Ubuntu 23.10 and newer default to
kernel.apparmor_restrict_unprivileged_userns=1, so bwrap cannot build a
sandbox even with bubblewrap installed, and Required refuses. On such a host
the capability message read "SRT helper closed its control channel before
launch" with "run install_srt_runtime.py" as the remedy, which the user had
already done successfully: a dead end on what is now a very common desktop.
The Linux path now names the missing binaries when any are missing, and names
the AppArmor restriction when they are all present, without touching host
policy. SRT_TOOL_ISOLATION.md says the same, since it already told users to
act "if the capability message requests them" and the message never did.

linux-native runs on ubuntu-22.04, which predates the restriction, so add a
linux-userns-restricted job on ubuntu-24.04 that reimposes the stock sysctl
and asserts the refusal is clean and the message actionable.

Also restore coverage the branch had moved off the sandbox path. Five
grandchild-teardown tests in test_tool_output_streaming.py ran with
disable_sandbox=True, which is Full access: it swaps _sandbox_preexec for
_bypass_preexec, so they exercised a teardown no user gets and would have
kept passing if the sandboxed one regressed. They run in Required again, kept
portable by the module's own passthrough fixture. The two truncation tests in
test_tool_result_fits_window.py take the strongest mode the host authorizes
rather than Full, so the process cap their comments rest on is real again.
test_bypass_permissions.py gains the invariant its moved seam stopped
checking: a backend that dropped the process guard now fails a test.

Finally, the per-call SRT badge said "OS isolation" while the pill above it
said "Preview OS isolation" for the same run; os_sandbox reports SRT as
preview and unqualified everywhere, so the badge should not read stronger.
Register the allow_network marker it warns about too.
@Etherll
Etherll marked this pull request as ready for review September 8, 2026 13:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-08T13:40:51.641954Z 32bc84c 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.

@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: 32bc84c188

ℹ️ 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".

),
};
} else {
await useChatRuntimeStore.getState().refreshToolIsolationCapability();

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 Avoid forcing a full isolation probe on every code-tool send

Whenever Python or Terminal is enabled, this unconditional refresh calls /tool-isolation/capability, whose route invokes _read_tool_isolation_capability(force=True). That bypasses the 60-second probe cache and repeats the native SRT/filesystem probe for every message—including the potentially two-minute scan that startup warmup is intended to pay once—so ordinary code-tool chats can stall before every model request, and concurrent tabs serialize repeated probes behind the probe lock. Routine dispatch should consume the cached capability, reserving a forced probe for the explicit “Check again” action; launch-time admission already revalidates the capability.

Useful? React with 👍 / 👎.

@danielhanchen

Copy link
Copy Markdown
Member

Opened #10526 as a smaller alternative for Linux and macOS only, so the two can be compared directly rather than this one carrying every platform at once.

It reuses the parts of this PR that are clearly right: the launch contract shape, the backend-owned execution record, the live probe with owned positive and negative controls, and the honest Preview labelling. It drops the Node dependency, the vendored package and integrity manifest, the HTTPS allowlist proxy, and Windows. 2,625 lines of product code against 8,700 here.

Two differences worth your view, since they are policy rather than implementation:

  1. It defaults to auto rather than fail-closed. Ubuntu 23.10 and newer ship kernel.apparmor_restrict_unprivileged_userns=1, so bubblewrap cannot build a sandbox on a large share of current Linux desktops even when installed. I verified this on my own box: bubblewrap 0.9.0 present, probe fails at uid_map. Fail-closed would take working tools away from all of those users until they find the Limited toggle, which is the breaking change you and Etherll discussed above.
  2. It keeps the network and confines only the filesystem, which is what removes the 1,944 line proxy and its 1,879 lines of tests. The record says network_policy = "unrestricted" rather than staying quiet about it.

None of that makes this PR wrong, and it does not cover Windows, which is genuinely hard and where SRT is the better answer. My suggestion is still the split from my earlier comment: land the isolation contract and one platform backend first, then the proxy, then Windows once srt-win wfp verify stops timing out on windows-2022.

Separately, I pushed 7f11049 here to clear the red CI. Three causes, none of them the isolation work:

  • pre-commit's prettier wrapped useSandboxImage(pythonToolImagePath(...)) across lines, and two guards matched that call as literal source text. Both are whitespace-tolerant now, the way the authFetch assertion beside one of them already was.
  • tests/studio/playwright_chat_ui.py still expected the old Full-access copy ("the code sandbox") and the old button label ("I understand"). That one file failed the Linux, macOS and Windows chat lanes.
  • desktop-native (windows-2022) is still failing on srt-win wfp verify --target 127.0.0.1:54322 timed out after 30000ms. That one needs a Windows host and is untouched.

The same commit adds the AppArmor diagnosis to the capability message, since the previous text told a stuck user to run the installer they had already run successfully, and restores four negative controls the branch had moved off the sandbox path (five grandchild-teardown tests were running with disable_sandbox=True, which is Full access and swaps _sandbox_preexec for _bypass_preexec, so they exercised a teardown no user gets).

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