No supported public contract currently maps a Windows Sandbox ID to a host-side HWND, host client PID, or durable client-connection identifier.
The Windows Sandbox CLI defines the Sandbox ID only as the identifier used by Sandbox commands such as list, connect, exec, share, ip, and stop. Its documented output does not include a host window handle, process ID, connection ID, or corresponding event field.^1^
Identifier scope
For the documented CLI:
-
wsb startcreates the Sandbox and returns its Sandbox ID. -
wsb listreports IDs for the current user's Sandbox sessions. -
wsb connect --id <id>opens a new remote-session window. -
wsb stop --id <id>terminates that Sandbox and closes its desktop window.^1^
Therefore, treat the ID as an identifier for the Sandbox environment, not for a particular client window or connection. The documentation does not define:
- an ID-to-
HWNDor ID-to-host-PID query; - a window property containing the Sandbox ID;
- stability of an associated client process across reconnects;
- a connection-generation identifier;
- an ETW or Windows Event Log correlation schema.
The CLI itself is described as an early/preview command-line feature in the newer Store-delivered Sandbox available from Windows 11 24H2.^2^
Why Win32 window enumeration cannot complete the mapping
GetWindowThreadProcessId supports the reverse lookup from an already-known HWND to the thread and process that created that window.^3^ It does not expose Sandbox metadata, so enumerating windows and retrieving their PIDs cannot produce a supported correlation to a particular Sandbox ID.
Matching by process name, title text, creation time, window order, or by observing the process launched around wsb connect would consequently be heuristic. It could break when:
- the client reconnects or is replaced;
- more than one client window exists;
- window titles or implementation details change;
- another process brokers or owns the visible window.
Such heuristics should not be used as an identity or security boundary.
Newer automation tooling does not provide that contract
The WinApp CLI can bind its operations to a Sandbox ID with --expect-sandbox, but this checks that the expected Sandbox is running; it does not provide session ownership or boot-identity guarantees. The documentation specifically says to use a new GUID for each wsb start, because restarting under the same GUID is not detected.^4^
For example:
$id = [guid]::NewGuid().ToString()
wsb start --id $id
winapp run . --on sandbox --expect-sandbox $id
winapp target snapshot sandbox --json can report readiness and guest windows without reconnecting the client. However, the reported UI PIDs and handles are guest-side identifiers, not host client-window identifiers. The same documentation notes that several client windows can make capture ambiguous and that the caller must resolve the candidates; it does not document a Sandbox-ID-to-host-HWND association.^4^
Practical supported boundary
If the tool needs to control a known Sandbox, keep and use the Sandbox ID only with documented wsb operations. Generate a fresh GUID for each launch if the tool needs to distinguish its own Sandbox generation:
$id = [guid]::NewGuid().ToString()
wsb start --id $id
wsb connect --id $id
wsb list --raw
# Later:
wsb stop --id $id
If the requirement specifically needs the host HWND—for example, to position, embed, monitor, or capture that exact client window—there is no documented supported mapping for package version [IP Address] in the available public interface. A formal product commitment or confirmation would require a Microsoft support case or a Windows Sandbox feature request; an implementation discovered through window enumeration would remain unsupported unless Microsoft publishes a corresponding API contract.
References