Skip to content

Studio: run the isolated Windows Terminal on cmd.exe with stock git when Git Bash cannot start in MXC - #12164

Merged
danielhanchen merged 11 commits into
mainfrom
studio-mxc-cmd-terminal
Sep 28, 2026
Merged

danielhanchen merged 11 commits into
mainfrom
studio-mxc-cmd-terminal

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

On Windows with MXC isolation (the AppContainer + DACL tier, opted into with UNSLOTH_MXC_ALLOW_DACL_FALLBACK=1), the Terminal never actually runs isolated. Git Bash cannot start inside the container (microsoft/mxc#1061), so since #12021 Auto falls back to software safeguards: bash on the host, which can read and write outside the chat's folder. This PR runs the Terminal isolated on the stock cmd.exe with the stock Git for Windows instead, when that is the case. No custom or patched shell is shipped.

Why stock git needed more than switching the shell

Stock git.exe starts under cmd inside MXC, but every repo command fails with unable to get current working directory: Permission denied:

  • Git for Windows resolves its cwd with GetFinalPathNameByHandleW(..., VOLUME_NAME_DOS) (compat/mingw.c, mingw_getcwd). Inside the container the drive-letter translation is denied; VOLUME_NAME_NT works, so it is the mount manager lookup, not file access.
  • Its fallback, GetLongPathNameW, needs to list every parent folder. Granting that on the parents does not work under the user profile and would expose the profile listing, so it is not used.
  • Running from a drive root fixes it: GetLongPathNameW("Z:\") has no parent to look up. Measured with stock git in the runner temp folder and in C:\Users\<user>\studio_sandbox.

Two more things only show up with cmd:

  • process.commandLine was built with subprocess.list2cmdline, which escapes embedded " as \". cmd does not understand that, so any quoted path broke. It also made the cmd capability probe's isolation controls meaningless: the same command line fails to read or write the outside file on the host too, so "denied" proved nothing.
  • Git runs hooks through Git for Windows' own sh.exe, which cannot start in the container, so a repo with a hook could not commit.

What changes

  • New mxc_drive_alias.py: for each cmd Terminal launch Studio maps a free drive letter to the session workdir with DefineDosDeviceW, verifies it with QueryDosDeviceW, and removes it with an exact-match remove when the launch ends. Letters already defined, in use, or reserved for a persistent network drive are skipped; concurrent launches of one workdir share a letter; a record under mxc-runtime/ (locked across processes) lets a later Studio process remove a mapping left by a crashed one, only when that process is gone and the mapping still names its folder. A mapping Studio did not create is never removed. If no letter can be mapped the launch still runs isolated; only git repo commands fail.
  • mxc_policy.py: cmd Terminal plans run the System32 cmd.exe (never COMSPEC) with "<cmd.exe>" /d /s /c "<command>", so quotes arrive as written and AutoRun is off. process.cwd is the drive root; every grant, scan and identity check still uses the real folder, and the alias is re-checked against the folder's identity at dispatch. Other workloads keep list2cmdline.
  • mxc_probe.py: the cmd probe goes through the same serializer and drive alias as production, and must write a file through a quoted redirect and start from the alias, so a probe with broken quoting fails instead of passing.
  • tools.py: the Terminal picks a profile per call. On Windows, when the DACL opt-in is on, Git Bash's MXC verdict is the MSYS failure and cmd qualifies, it is cmd_isolated:
    • argv [System32\cmd.exe, "/c", command], trailing newline stripped, multi-line commands refused with a clear message (cmd would only run the first line);
    • env without Git Bash's userland on PATH, plus core.hooksPath=NUL (through GIT_CONFIG_COUNT), an empty GIT_PAGER, an editor that fails at once, and no credential prompts. Git installed for Git Bash only (not on PATH) is found through the install bash came from, under the same Program Files trust check;
    • the blocklist checks the command as cmd and as bash, with and without ^ escapes, and both it and the approval checks also read it the way cmd runs it: ' is an ordinary character, a leading @ only turns the echo off, and the command after an IF condition, FOR ... DO or CALL is at command position (keywords in any case);
    • it is never replayed on the host: in Auto, a failure to isolate at launch time is refused, not run unsandboxed, unless the user approved this command reaching host paths.
  • Unisolated cmd launches (approved host access, and hosts without Git where the Terminal already used cmd) also get cmd's own quoting now, so a quoted path no longer breaks there.
  • routes/inference.py: the Terminal description tells the model the shell is cmd for those requests (all three places the Full access description is applied). Only the first request in a process can wait on the probe; later ones reuse the last profile and refresh it on a background thread once it is four minutes old. A tool list without the Terminal never probes.
  • UNSLOTH_MXC_TERMINAL_CMD=0 keeps today's behaviour. Linux, macOS, Full access, hosts without MXC, and hosts where the opt-in is off are unchanged.

Results

GitHub windows-latest (Windows Server 2025, 24H2, build 26100), pinned MXC v0.8.0, --prepare-host, the DACL opt-in, the real tools._bash_exec in Auto with Git for Windows installed, main at 7c8e50a vs this branch. The same commands in both arms:

Command main this PR
Terminal mode software safeguards (bash on the host) os_isolated (MXC, cmd.exe)
git init, commit -qm "quoted msg", log, status works works
add, diff --cached --stat, stash, stash list works works
commit in a repo with a pre-commit hook works, hook runs on the host works, hook not run
git clone --depth 1 over HTTPS works works
"C:\Program Files\Git\cmd\git.exe" --version works works
read a file outside the workdir allowed denied
write outside the workdir allowed denied
multi-line command runs refused with a message

With the opt-in off both arms are identical (bash, software safeguards). Per-command time inside MXC was 0.4 to 0.8 s after the first call in that run, which also had the runtime folders pre-granted as in #12121; without that change each launch adds MXC's per-launch permission walk.

MXC suites on the same runner (non-native and native_mxc, 307 tests): 3 failures, the same 3 that fail on main (229 tests there, before the new files):

  • test_mxc_windows_backend.py::test_selected_python_spelling_is_preserved_in_trusted_policy
  • test_mxc_windows_backend.py::test_terminal_policy_preserves_constructed_shell_argv
  • test_mxc_native_windows.py::test_native_mxc_powershell_variants_pass_live_terminal_controls[powershell.exe]

Linux: 4318 passed, 20 skipped across tests/test_mxc_*.py, tests/test_sandbox*.py, the Terminal, permission and tool prompt suites, including the new test_mxc_drive_alias.py, test_mxc_cmd_command_line.py and test_windows_cmd_terminal_profile.py.

Not covered

  • MXC's BaseContainer tier (25H2+ with the OS contract) is untested, so hosts that are isolated without the DACL opt-in keep Git Bash.
  • Credential helpers and ssh remotes inside the container; a public HTTPS clone works.
  • Git features that start other programs through sh (filters, external diff tools) fail inside the container like hooks would; they are not turned off.
  • Paths git stores as absolute (for example git worktree add) name a drive letter that only exists during that call.
  • If isolation stops qualifying between two calls of one chat, the next call can be a different shell than the description the model saw for that turn; the description can lag a change by a few minutes.
  • The blocklist and approval checks are defence in depth, not a cmd parser: %VAR:~n,m% substring expansion can still spell a command, as ${X:0:1} can under bash today. MXC is the boundary, and it limits writes to the chat folder.

Git for Windows cannot resolve its working directory inside an MXC AppContainer: the drive-letter form of GetFinalPathNameByHandleW is denied and the GetLongPathNameW fallback lists every ancestor. A cmd Terminal launch now runs from a drive letter mapped onto the canonical workdir with DefineDosDeviceW, refcounted per workdir, recorded for crash cleanup and removed with an exact match.
list2cmdline escapes embedded quotes as \" which cmd cannot parse, so a quoted path broke and the cmd probe's denied read and write passed without being attempted. A cmd /c Terminal plan now runs System32's cmd.exe as "cmd.exe" /d /s /c "<payload>", refusing NUL, multi-line and oversize payloads. build_launch_request takes an optional drive-root cwd alias naming the workdir (stock git cannot resolve a nested cwd in the container); grants and identities stay canonical and the alias is rechecked at dispatch. The cmd probe adds a quoted-redirect positive control.
…nnot start in MXC

When the MXC probe reports that Git Bash (MSYS2) cannot start in the container and cmd.exe qualifies, the Terminal runs System32 cmd.exe inside MXC instead of Git Bash with software safeguards. The profile is chosen once per call, so the blocklist lexer, env and argv agree, and per request for the tool schema, so the model is told it has cmd. Git gets non-interactive defaults (core.hooksPath=NUL, no pager or editor) because its hooks, pager and editor start through MSYS sh.exe. UNSLOTH_MXC_TERMINAL_CMD=0 keeps the host shell.
Never replay an isolated cmd command on the host, screen it with every lexer reading and with ^ escapes removed, and have the approval classifiers read it the way cmd splits it. Strip the trailing newline models send, switch from Git Bash only on the measured DACL tier, and do not probe for a tool list without the Terminal. Run the cmd probe from the drive alias like production. Keep cmd's own quoting on host launches too. Keep a shadowed alias removable, keep a record whose mapping could not be removed, reclaim a stale record only once its mapping is gone, and skip persistent network drive letters. Unit tests never map real drive letters; the alias and native tests opt back in.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 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 ⚠️ Failed 2026-09-28T10:53:15.486229Z 123d9fe New commits
🔒 Security Review ✅ Completed 2026-09-28T09:10:24.545801Z 84b5db6 Manual request

Security findings

Advisory findings (1)

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
🔒 Security Review 🔄 Running since 2026-09-28T05:06:49.069507Z d20e463 PR opened
ℹ️ 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 added a commit to LeoBorcherding/unsloth that referenced this pull request Sep 28, 2026
@shimmyshimmer shimmyshimmer added edge case# new-feature# regresses# security# Moves a security boundary: sandbox, allowlist, permission or network guard labels Sep 28, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security 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: 84b5db62da

ℹ️ 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 +293 to +295
command_line = f'"{cmd_path}" /d /s /c "{payload}"'
if len(command_line) > MAX_COMMAND_LINE:
raise MxcPolicyError("the Terminal command exceeds the Windows command-line limit")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Enforce cmd.exe's 8191-character command limit

For an isolated cmd payload whose assembled command line is between 8,192 and 32,767 characters, this check accepts the request even though cmd.exe has a documented maximum command-line length of 8,191 characters. Such calls can fail or be truncated instead of running the submitted command; use the cmd-specific bound (and count UTF-16 units rather than Python code points) before dispatch. See Microsoft's documented limit: “The maximum length ... is 8191 characters.”

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

cmd /c over its limit refuses the whole line with "The command line is too long." and runs nothing; the truncation cases are long lines inside batch files, which this path never writes. The model gets that error back and can shorten the command.

@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 Security Review

Here are some automated security review suggestions for this pull request.

Reviewed commit: 84b5db62da

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread studio/backend/core/inference/tools.py Outdated

def _cmd_reading(command: str) -> str:
"""How cmd splits a command for the POSIX classifiers: ' is an ordinary character and ^ only escapes."""
return command.replace("^", "").replace("'", " ")

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 Security Review

P2 Badge Security: Reject cmd variable expansion before auto-running

Requires Windows DACL fallback, the new cmd_isolated profile, tools, and auto approval. cmd.exe expands %VAR:~start,len% before execution, but this normalizer handles only ^ and '. The fixed Git environment can therefore spell del, e.g. %GIT_EDITOR:~12,1%%GIT_CONFIG_KEY_0:~3,1%%GIT_EDITOR:~3,1% /q victim.txt. The blocklist and high-risk classifier accept the literal, so model or prompt-injected output can delete a project-workdir file without confirmation. Expand or reject cmd variables before both checks.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same class as bash parameter expansion on the existing profile: ${X:0:1}${Y:1:1} -rf x is not high risk there either. The classifiers are defence in depth; what this can reach is the chat workdir, which the container already lets the Terminal and the Python tool write. Outside it MXC denies the write.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@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: e6602ce168

ℹ️ 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 +244 to +248
request = (
mxc_policy.build_launch_request(probe_plan, cwd_alias = lease.root)
if lease
else mxc_policy.build_launch_request(probe_plan)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Refuse the cmd profile when no drive alias is available

When alias acquisition returns None—for example because UNSLOTH_MXC_DRIVE_ALIAS=0, all candidate letters are occupied, or the alias record cannot be locked—this branch still probes and qualifies cmd from the canonical nested workdir. The probe exercises only cmd built-ins, so it passes even though _workdir_alias documents that stock Git needs the drive root; production then also launches without an alias while the tool schema promises that Git works, causing every Git command to fail. Treat a missing alias as an unavailable cmd profile (and likewise refuse the production launch) rather than silently building the request without it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Without a letter the launch still runs isolated and only git repo commands fail, with git's own error; the record names the missing alias. Refusing the cmd profile would send the Terminal back to bash on the host, which is the unsandboxed case this PR removes.

Comment on lines +21336 to +21338
# Chosen once, so the blocklist, env and argv all agree on the shell that will run this call.
profile = _terminal_profile(disable_sandbox)
if profile == "cmd_isolated":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Pin the advertised terminal profile through execution

The request schema selects and advertises a shell earlier, but this line independently resolves the profile again when the model's tool call executes. If the 30/300-second probe cache expires during a long generation, or another launch invalidates it, a transient capability change can switch between the advertised Bash and cmd profiles; the resulting payload may be refused, interpreted by the wrong shell, or lose the required isolation behavior applied only to cmd. Carry the request's selected profile into execution instead of re-probing here.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Listed under Not covered in the description. The verdict that picks cmd is cached for hours, so a flip needs the capability itself to change mid-turn, and the call that follows still runs under the profile its own checks were done for.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@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: 2481cf8674

ℹ️ 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 +21417 to +21418
if profile == "cmd_isolated":
shell_argv, _scratch_name = [_windows_system_cmd(), "/c", command], None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Match cmd output encoding before decoding as UTF-8

When cmd_isolated is selected on a Windows host whose active console code page is not UTF-8, cmd built-ins emit redirected output in that code page while _bash_exec still opens the pipe with encoding="utf-8", errors="replace". Commands such as echo café or dir over localized filenames therefore return replacement characters or mojibake; these same hosts previously used Git Bash's UTF-8 output. Switch cmd to code page 65001 before the payload or decode its output using the actual cmd code page.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

git, the reason this profile exists, writes UTF-8, and that is what is decoded. Switching cmd to 65001 or decoding as the OEM page would garble git's output instead; cmd built-ins printing non-ASCII in the OEM page is the same on the existing cmd fallback.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

… cmd isolation required unless host access was approved
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@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: 4c9397042a

ℹ️ 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 +5734 to +5735
text = _CMD_ECHO_OFF_RE.sub("", command.replace("^", "").replace("'", " "))
return _CMD_CONTROL_RE.sub(" & ", text)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict CALL and DO rewriting to command positions

Under the cmd_isolated profile, this unconditional regex substitution rewrites CALL and DO even when they are ordinary arguments, so benign commands such as echo call rmdir or echo do rm become echo & rmdir or echo & rm for the hard-block scan and are refused although cmd would only echo the text. Track command position before treating CALL as control flow, and recognize DO only as part of a FOR construct.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Deliberate over-approximation: the extra reading only adds refusals, and a refusal needs a blocked command word right after an unquoted call or do argument, as in echo do rm. A quoted message is untouched, and the refusal names the word, so the model can quote it.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 28, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@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: 4c9397042a

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

entry[2] += 1
return AliasLease(entry[0], entry[1])
# Covered by another definition: never touch that one; ours is removed when its leases end.
_shadowed[(entry[0], key)] = _active.pop(key)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retire shadowed leases after reclaiming their mapping

When another process temporarily covers an active drive letter, this moves the old entry to _shadowed, but the immediately following _reclaim ignores _shadowed and therefore removes that original mapping and its record. The old AliasLease remains live; if the letter is subsequently reused before that lease is released, its cleanup can delete the new owner's recovery record, or even remove the new live mapping when it points to the same workdir. Mark the shadowed lease as already unmapped when reclaiming it, or verify record ownership before removal.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Needs another program to define a DOS device over the letter Studio mapped while a launch holds it, and then the same letter to be reused for the same workdir before that lease ends. Nothing does that in the same logon session; the exact-match removal still never touches a mapping to another folder.

# Conflicts:
#	studio/backend/core/inference/sandbox_windows_mxc.py
@danielhanchen
danielhanchen merged commit a19dae7 into main Sep 28, 2026
1 check was pending
@danielhanchen
danielhanchen deleted the studio-mxc-cmd-terminal branch September 28, 2026 10:52
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…hen Git Bash cannot start in MXC (unslothai#12164)

* Studio: alias the MXC cmd Terminal workdir to a drive root

Git for Windows cannot resolve its working directory inside an MXC AppContainer: the drive-letter form of GetFinalPathNameByHandleW is denied and the GetLongPathNameW fallback lists every ancestor. A cmd Terminal launch now runs from a drive letter mapped onto the canonical workdir with DefineDosDeviceW, refcounted per workdir, recorded for crash cleanup and removed with an exact match.

* Studio: pass cmd Terminal commands to MXC with cmd's own quoting

list2cmdline escapes embedded quotes as \" which cmd cannot parse, so a quoted path broke and the cmd probe's denied read and write passed without being attempted. A cmd /c Terminal plan now runs System32's cmd.exe as "cmd.exe" /d /s /c "<payload>", refusing NUL, multi-line and oversize payloads. build_launch_request takes an optional drive-root cwd alias naming the workdir (stock git cannot resolve a nested cwd in the container); grants and identities stay canonical and the alias is rechecked at dispatch. The cmd probe adds a quoted-redirect positive control.

* Studio: run the Windows Terminal isolated on cmd.exe when Git Bash cannot start in MXC

When the MXC probe reports that Git Bash (MSYS2) cannot start in the container and cmd.exe qualifies, the Terminal runs System32 cmd.exe inside MXC instead of Git Bash with software safeguards. The profile is chosen once per call, so the blocklist lexer, env and argv agree, and per request for the tool schema, so the model is told it has cmd. Git gets non-interactive defaults (core.hooksPath=NUL, no pager or editor) because its hooks, pager and editor start through MSYS sh.exe. UNSLOTH_MXC_TERMINAL_CMD=0 keeps the host shell.

* Studio: harden the isolated cmd Terminal after review

Never replay an isolated cmd command on the host, screen it with every lexer reading and with ^ escapes removed, and have the approval classifiers read it the way cmd splits it. Strip the trailing newline models send, switch from Git Bash only on the measured DACL tier, and do not probe for a tool list without the Terminal. Run the cmd probe from the drive alias like production. Keep cmd's own quoting on host launches too. Keep a shadowed alias removable, keep a record whose mapping could not be removed, reclaim a stale record only once its mapping is gone, and skip persistent network drive letters. Unit tests never map real drive letters; the alias and native tests opt back in.

* Studio: screen cmd's literal single quotes in the blocklist and keep alias rollback on record cleanup errors

* Studio: read past cmd IF conditions in the blocklist and find Git installed for Git Bash only

* Studio: read past cmd's @ echo prefix in the Terminal checks

* Studio: fold cmd FOR/DO and IF CMDEXTVERSION in the blocklist and keep the Terminal probe off the request path

* Studio: read cmd IF, FOR DO and CALL in every Terminal check and keep cmd isolation required unless host access was approved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

edge case# new-feature# regresses# security# Moves a security boundary: sandbox, allowlist, permission or network guard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants