Skip to content

proposal: syscall: update Windows SysProcAttr for recent process creation features #80415

Description

@rsc

Proposal Details

I propose to update syscall.SysProcAttr on Windows to let callers control the following process creation parameters:

  • The job object list for the new process.
  • The console for the new process.
  • The desktop for the new process.
  • The AppContainer configuration for the new process.
  • (Added, July 28) The experimental sandbox configuration for the new process.

In general package syscall is frozen. However, one exception is details that affect process creation through os/exec, because otherwise the only way to make such calls is to fork both syscall and os/exec.

The API change is these new fields in syscall.SysProcAttr on Windows:

	Jobs                       []Handle            // if non-nil, start the process with this job object list
	Console                    Handle              // if non-zero, start the process connected to this console
	Desktop                    string              // if non-empty, start the process on the named desktop
	AppContainer               *AppContainer       // if set, create AppContainer process with this metadata
	Sandbox                    *Sandbox            // if non-nil, start the process in the described sandbox

And a new type, AppContainer:

// An AppContainer defines parameters for creating a process in an AppContainer.
// It is a safe Go version of the Windows SECURITY_CAPABILITIES structure.
// See https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-security_capabilities.
type AppContainer struct {
	SID          *SID
	Capabilities []SIDAndAttributes
 }

We could instead define SecurityCapabilities to be the literal Windows struct, but that Windows struct is unsafe and also may possibly change in the future. The #if in the documentation page definition look scary. It seemed cleaner to give it an appropriate name and use a Go slice. Then if the actual struct passed to the Windows call varies by OS version, that's an implementation detail and not an API detail.

And also a new type Sandbox (added July 28):

// A Sandbox defines parameters for creating a process in an experimental sandbox.
// See https://learn.microsoft.com/en-us/windows/win32/secauthz/createprocessinsandbox.
type Sandbox struct {
    Identity string  // sandbox name
    Spec     []byte  // FlatBuffer-encoded specification; see Microsoft docs
}

That is the entire API change. I have used the AppContainer part of this API successfully to implement basic sandboxing of Windows programs using AppContainer. I have not used the Sandbox part since Microsoft has not yet enabled the API on my Windows system (you can call it but it says not supported), but given the recent launch of https://github.com/microsoft/mxc, it seems likely they will enable it in the coming six months, so having it ready for the Feb 2027 Go release seems worthwhile.

There is no support in package syscall for constructing a sandbox spec. We could add that instead to golang.org/x/sys/windows, where it can be more easily updated. This proposal is concerned with the minimal amount necessary to enable use of the new functionality through os/exec.

The AppContainer details in this proposal are a safer version of the accepted proposal #65611. I suggest we do the API in this proposal instead of #65611, because in general we keep syscall.SysProcAttr type-safe, even on Windows.

The job object details in this proposal mostly match the undiscussed proposal #79927.

The desktop details in this proposal address the feature requested in #42836.

The implementation (except for Sandbox) is at CL 801640.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Active

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions