mxc icon indicating copy to clipboard operation
mxc copied to clipboard

.NET SDK: PowerShell samples exit with code 127 and no error under the default UI policy

Open trevotai-amd opened this issue 4 weeks ago • 0 comments

Relevant area(s)

Windows

Brief description of your issue

With the default UI policy, a process container blocks Win32k access, so powershell.exe fails to initialize (STATUS_DLL_INIT_FAILED, 0xC0000142). Through wxc-exec this prints a helpful hint to set ui.disable: false. Through the .NET SDK there is no output and no error, only exit code 127, plus an "Application Error" dialog on the host. Three of the ten .NET samples on main hit this as published (network, stdio-streaming, pty-interactive), because they run PowerShell and set no UI policy.

Python's ctypes import fails the same way under the default policy (DLL load failed while importing _ctypes), which may be worth a docs note.

Related: #1465 reports the same error code from a different cause (non-interactive sessions, even with ui.disable=false); ours is a normal interactive session with the default UI policy. #1629 sees Node fail with 0xC0000142 when UI is disabled. #1656 proposes carrying a remediation field on create-and-run errors, which would let the SDK surface the hint that wxc-exec already prints.

Versions: MXC 1.0.0 and 1.0.1 (NuGet Microsoft.Mxc.Sdk, npm @microsoft/mxc-sdk), Windows 11 26300.9711.

Steps to reproduce

  1. Clone main, open samples/run-with-containment-of-network/dotnet, and dotnet run (with Rust installed, or after switching the SDK reference to NuGet Microsoft.Mxc.Sdk 1.0.1).
  2. For comparison, create ps.json and run wxc-exec ps.json:
    {"version": "1.0.0", "containment": "processcontainer",
     "process": {"commandLine": "powershell -NoProfile -Command Write-Output hi", "timeout": 60000},
     "network": {"egress": {"default": "deny"}, "ingress": {"default": "deny", "hostLoopback": "deny"}}}
    

Expected behavior

Either the samples work as published (they set Ui = new UiPolicy { Disable = false }), or the SDK surfaces the same diagnostic that wxc-exec prints, instead of a bare exit code.

Actual behavior

.NET sample: no output, exit code 127, and a host dialog:

powershell.exe - Application Error
The application was unable to start correctly (0xc0000142).

wxc-exec:

The target executable exited with STATUS_DLL_INIT_FAILED (0xC0000142). This often means the sandbox is blocking
Win32k system calls (UI subsystem access), which is often required to initialize. Enable UI access in your sandbox
policy: set `ui.disable: false` in the JSON config, or `ui.allowWindows: true` if you are using the SDK's SandboxPolicy.

Adding Ui = new UiPolicy { Disable = false } to the sample makes it work (prints network access blocked by policy).

trevotai-amd avatar Nov 03 '26 23:11 trevotai-amd