Repository navigation
feat(mxc): support exec in Windows ProcessContainer sandboxes - #5859
Conversation
Run additional commands in Ready MXC ProcessContainer sandboxes. Preserve
literal arguments, working directory, environment, and exact Windows exit
statuses. Stream stdin, stdout, and stderr. Stop expired commands and close
the SSH relay when the client disconnects. Report truncated output and bound
retained exec records. Relaunch stopped or retired sandboxes with their
existing workspace.
The Windows supervisor uses internal SSH for additional commands. Its SSH
handler does not attach clients to the sandbox's original program.
Manual reproduction on Windows x64 ProcessContainer
Start the rebuilt native MXC gateway with allow_driver_config enabled.
Use the rebuilt openshell.exe. Register the gateway's CLI profile and
use that name for $gateway below. Build
mxc-forwarding-agent.exe with windows:build:mxc-fixtures:x64 and copy it
into C:\work\mxc-whoami. Save this policy as C:\work\mxc-whoami-policy.yaml.
version: 1
filesystem_policy:
include_workdir: false
read_only: []
read_write:
- 'C:/work/mxc-whoami'
ui:
allow_graphical_ui: true
Use a fresh workspace and run the fixture as the sandbox's first program
so it stays Ready. The fixture exits when exit.txt appears.
$gateway = 'mxc-exit-fixed'
$work = 'C:\work\mxc-whoami'
$fixture = "$work\mxc-forwarding-agent.exe"
$config = @{ mxc = @{ cwd = $work; command = @($fixture, '--exit-on-file', "$work\launch.txt", "$work\exit.txt") } } | ConvertTo-Json -Depth 4 -Compress
openshell.exe --gateway $gateway sandbox create --name whoami-check --detach --no-auto-providers --policy 'C:\work\mxc-whoami-policy.yaml' --driver-config-json $config
openshell.exe --gateway $gateway sandbox list
On Windows PowerShell 5.1, pass ($config.Replace('"', '\"')) as the value
of --driver-config-json. Wait for whoami-check to show Ready. Paste the
following as one block so the prompt cannot overwrite the exit code.
& {
openshell.exe --gateway $gateway sandbox exec whoami-check --no-tty -- 'C:\Windows\System32\whoami.exe'
'whoami exit: {0} (0x{0:X8})' -f $LASTEXITCODE
}
Expect an account name and exit 0. The executable imports USER32.dll.
On the tested host, the default UI policy caused 0xC0000142
(STATUS_DLL_INIT_FAILED) both as the first program and through exec.
The same first-program result reproduced before this exec change.
Enabling graphical UI in the test policy let both launch paths succeed.
Manual results on the rebuilt x64 gateway
- Run cmd.exe /d /c "exit /b $code" through sandbox exec --no-tty for
0, 7, 255, 256, and -1073741819. All five returned exactly. The last
is Windows status 0xC0000005. The old gateway returned 2147483647.
- cmd.exe /d /c ver printed the Windows version and returned 0.
findstr.exe /r '.' on the starter's text marker printed the line and
returned 0. A search for an absent literal returned 1.
- A missing executable and an existing text file each gave a launch
diagnostic naming the file and returned 1.
- The native probe printed the literal argument 'spaces & %PATH% | literal',
reported the requested working directory containing a space, and
preserved the environment value 'two words & more'. Each returned 0.
- The filesystem probe with graphical UI enabled allowed reads and
writes inside the workspace and denied both outside it.
Automated Windows x64 verification
- The native release build verified all four Windows binaries.
- The MXC boundary suite passed 42 tests with 2 ignored.
- The supervisor-process suite passed 65 tests.
- The real ProcessContainer exec-restart smoke passed with the consolidated
native probe. It verified argv, cwd, env, both output streams, stdin,
exit status, timeout cleanup, and workspace retention across both restarts.
- Earlier x64 runs passed 11 focused gateway relay tests and the real
gateway-kill scenario. The smoke checks above cover the final source.
Signed-off-by: Kaylee Lubick <klubick@nvidia.com>
shailendra-nv
left a comment
There was a problem hiding this comment.
I verified 6cb78ff8 with a native Windows ARM64 release build and the real MXC ProcessContainer exec-restart scenario (1 passed, 0 failed, 0 skipped). The scenario covered literal arguments, streaming I/O, 60,000 lines of stdout, full Windows exit codes, and exec after restarting from Completed and Stopped with the workspace retained.
Two focused tests reproduced output loss when a child closes stdin and a descendant that survives an exec timeout. The inline comments also describe a provisioning-timeout restart problem found by code review.
The Issue Acceptance check still needs a closing reference to an accepted issue that matches this PR’s ProcessContainer scope. #5468 already has state:accepted and also tracks Isolation Session support.
A timeout only stopped the original command. Any processes it started could keep running in the sandbox. Keep Tokio for launching commands and use a Windows Job Object to stop the command and its children together. Start the command paused and put it in the job before it can start any children. We considered the process-wrap library. Adding and maintaining another third-party dependency would cost more than it saved for this small amount of Windows code. The Windows test starts a real child process and checks that both processes stop while the sandbox stays ready. Signed-off-by: Kaylee Lubick <klubick@nvidia.com>
A command can stop accepting input while it is still writing output. If the caller sent more input, the closed pipe ended the connection and the caller lost the remaining output and the real exit code. Treat a closed input pipe as the end of the command's input. Keep reading client messages so the connection can still close normally, and keep sending stdout, stderr, and the command's exit code. The regression sends input twice after the pipe closes and checks that both output streams and exit code 7 reach the caller. Signed-off-by: Kaylee Lubick <klubick@nvidia.com>
When sandbox setup timed out, cleanup stopped the MXC runtime and kept its record for recovery. A retry used the old launch credentials, so MXC refused to restart the stopped runtime. Use the same credential refresh as a normal restart once cleanup finishes. Save the new credentials when the sandbox enters Starting so repeated requests for that same start reuse them. The regression runs timeout cleanup and checks that the retry sends a newer credential version matching the one the gateway saved. Signed-off-by: Kaylee Lubick <klubick@nvidia.com>
|
/windows-ci |
Summary
Enable
sandbox exec --no-ttyin Ready Windows MXC ProcessContainer sandboxes. Exec preserves literal arguments, working directory, environment, and full 32-bit Windows exit codes. It streams stdin, stdout, and stderr, reports spawn and output-delivery errors, and stops timed-out commands.sandbox startrelaunches the runtime with the workspace intact.This PR covers ProcessContainer. Isolation Session validation remains tracked in #5468. Fixes #5913
Verification
exec-restartpassed on MXC 1.0.0. It checked literal arguments, working directory, environment, streamed stdin and both output streams, 60,000 lines of complete stdout, spawn errors, nonzero and crash-style exit codes, timeout cleanup, and exec after restart from both Completed and Stopped with the workspace retained.cmd.exeandfindstr.exeoutput and exit codes, including Windows status0xC0000005. On the test host,whoami.exeprinted the account and returned 0 with graphical UI enabled in the test policy.gateway-killscenario also passed. An earlier ProcessContainer build worked on the ARM64 RTX Spark. Final-revision ARM64 and Linux validation are pending.Thanks