AppcontainerRunner: pass explicit env block to CreateProcess#386
Merged
Conversation
When process.env is specified in the config, encode it as a UTF-16 environment block and pass it to CreateProcess with CREATE_UNICODE_ENVIRONMENT. When empty, pass NULL (OS default).
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the Windows AppContainer runner to optionally pass an explicit UTF-16 environment block to CreateProcessW (with CREATE_UNICODE_ENVIRONMENT) when process.env is provided in the config, including proxy env-var injection without mutating global process state.
Changes:
- Refactors env handling into
encode_env_block()(UTF-16 env block serialization) andbuild_explicit_entries()(parseKEY=VALUE, inject/override proxy vars). - Wires the encoded env block into the
CreateProcessWcall when applicable; otherwise passesNULLto inherit the default environment.
Show a summary per file
| File | Description |
|---|---|
| src/wxc_common/src/appcontainer_runner.rs | Adds explicit env-block encoding/parsing and uses it when spawning the AppContainer child process. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 3
Comment on lines
53
to
62
| @@ -81,6 +61,36 @@ fn build_proxy_env_block(address: &crate::models::ProxyAddress) -> Vec<u16> { | |||
| block | |||
| } | |||
Comment on lines
+404
to
+417
| let env_block: Option<Vec<u16>> = if !request.env.is_empty() { | ||
| let entries = build_explicit_entries(&request.env, self.proxy_address.as_ref()); | ||
| Some(encode_env_block(&entries)) | ||
| } else if let Some(addr) = self.proxy_address.as_ref() { | ||
| // No explicit env but proxy is active -- inject only proxy vars. | ||
| let proxy_url = addr.to_url(); | ||
| let entries = vec![ | ||
| ("HTTP_PROXY".to_string(), proxy_url.clone()), | ||
| ("HTTPS_PROXY".to_string(), proxy_url), | ||
| ]; | ||
| Some(encode_env_block(&entries)) | ||
| } else { | ||
| None | ||
| }; |
Comment on lines
+400
to
+403
| // Environment block for the sandboxed child. | ||
| // If explicit env vars were provided, use only those (+ proxy injection). | ||
| // If only proxy is active (no explicit env), build a block with just proxy vars. | ||
| // Otherwise, pass NULL to inherit the default environment. |
bbonaby
approved these changes
May 22, 2026
Comment on lines
+400
to
+417
| // Environment block for the sandboxed child. | ||
| // If explicit env vars were provided, use only those (+ proxy injection). | ||
| // If only proxy is active (no explicit env), build a block with just proxy vars. | ||
| // Otherwise, pass NULL to inherit the default environment. | ||
| let env_block: Option<Vec<u16>> = if !request.env.is_empty() { | ||
| let entries = build_explicit_entries(&request.env, self.proxy_address.as_ref()); | ||
| Some(encode_env_block(&entries)) | ||
| } else if let Some(addr) = self.proxy_address.as_ref() { | ||
| // No explicit env but proxy is active -- inject only proxy vars. | ||
| let proxy_url = addr.to_url(); | ||
| let entries = vec![ | ||
| ("HTTP_PROXY".to_string(), proxy_url.clone()), | ||
| ("HTTPS_PROXY".to_string(), proxy_url), | ||
| ]; | ||
| Some(encode_env_block(&entries)) | ||
| } else { | ||
| None | ||
| }; |
Collaborator
There was a problem hiding this comment.
thought: we should probably do the same thing for base container. Adding the proxy env variables I mean, if they give it to us. If you can we can add it to #385 before we check it in
Member
Author
|
Closes: #346 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When process.env is specified in the config, encode it as a UTF-16 environment block and pass it to CreateProcess with CREATE_UNICODE_ENVIRONMENT. When empty, pass NULL (OS default).
#346
Microsoft Reviewers: Open in CodeFlow