Skip to content

BaseContainer: pass explicit env block to CreateProcessInSandbox#385

Merged
jsidewhite merged 1 commit into
mainfrom
jsidewhite/env_from_sdk_to_cpis_pr
May 22, 2026
Merged

BaseContainer: pass explicit env block to CreateProcessInSandbox#385
jsidewhite merged 1 commit into
mainfrom
jsidewhite/env_from_sdk_to_cpis_pr

Conversation

@jsidewhite

@jsidewhite jsidewhite commented May 22, 2026

Copy link
Copy Markdown
Member

When process.env is specified in the config, encode it as a UTF-16 environment block and pass it to Experimental_CreateProcessInSandbox with CREATE_UNICODE_ENVIRONMENT. When empty, pass NULL (OS default).

SDK: inject env dict into config.process.env instead of node-pty process inheritance to prevent secret leakage into the sandbox.

#218

Microsoft Reviewers: Open in CodeFlow

When process.env is specified in the config, encode it as a UTF-16
environment block and pass it to Experimental_CreateProcessInSandbox
with CREATE_UNICODE_ENVIRONMENT. When empty, pass NULL (OS default).

SDK: inject env dict into config.process.env instead of node-pty
process inheritance to prevent secret leakage into the sandbox.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 22, 2026 04:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates MXC’s Windows BaseContainer execution path and the TypeScript SDK spawn helpers to pass environment variables explicitly via the JSON config (and into Experimental_CreateProcessInSandbox), rather than inheriting them from the parent process environment.

Changes:

  • Rust: Build and pass a UTF-16 environment block to Experimental_CreateProcessInSandbox when process.env is present.
  • SDK: Inject the env argument into config.process.env and stop passing it via node-pty/child_process.spawn environment inheritance.
  • Workspace: Adds a Windows crate feature intended for environment-related Win32 APIs.
Show a summary per file
File Description
src/wxc_common/src/base_container_runner.rs Adds env-block encoding + passes env to BaseContainer create call.
src/Cargo.toml Enables an additional windows crate feature for environment APIs.
sdk/src/sandbox.ts Changes env propagation to flow through config (process.env) instead of executor process env inheritance.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 6

Comment on lines +47 to +62
fn encode_env_block(env_vars: &[String]) -> Vec<u16> {
let mut entries: Vec<(&str, &str)> =
env_vars.iter().filter_map(|e| e.split_once('=')).collect();

entries.sort_by(|(a, _), (b, _)| a.to_ascii_uppercase().cmp(&b.to_ascii_uppercase()));

let mut block = Vec::new();
for (key, value) in &entries {
for ch in format!("{}={}", key, value).encode_utf16() {
block.push(ch);
}
block.push(0);
}
block.push(0);
block
}
Comment on lines +47 to +62
fn encode_env_block(env_vars: &[String]) -> Vec<u16> {
let mut entries: Vec<(&str, &str)> =
env_vars.iter().filter_map(|e| e.split_once('=')).collect();

entries.sort_by(|(a, _), (b, _)| a.to_ascii_uppercase().cmp(&b.to_ascii_uppercase()));

let mut block = Vec::new();
for (key, value) in &entries {
for ch in format!("{}={}", key, value).encode_utf16() {
block.push(ch);
}
block.push(0);
}
block.push(0);
block
}
Comment on lines +47 to +62
fn encode_env_block(env_vars: &[String]) -> Vec<u16> {
let mut entries: Vec<(&str, &str)> =
env_vars.iter().filter_map(|e| e.split_once('=')).collect();

entries.sort_by(|(a, _), (b, _)| a.to_ascii_uppercase().cmp(&b.to_ascii_uppercase()));

let mut block = Vec::new();
for (key, value) in &entries {
for ch in format!("{}={}", key, value).encode_utf16() {
block.push(ch);
}
block.push(0);
}
block.push(0);
block
}
Comment thread src/Cargo.toml
Comment on lines 38 to 46
windows = { version = "0.62", features = [
"Win32_Foundation",
"Win32_Security",
"Win32_System_Com",
"Win32_System_Console",
"Win32_System_Environment",
"Win32_System_Ole",
"Win32_System_Threading",
"Win32_System_Pipes",
Comment thread sdk/src/sandbox.ts
Comment on lines +446 to +460
function injectEnvIntoConfig(
config: ContainerConfig,
env: { [key: string]: string | undefined },
): void {
if (!config.process) {
config.process = { commandLine: '' };
}
const entries: string[] = config.process.env ? [...config.process.env] : [];
for (const [key, value] of Object.entries(env)) {
if (value !== undefined) {
entries.push(`${key}=${value}`);
}
}
config.process.env = entries;
}
Comment thread sdk/src/sandbox.ts
Comment on lines +471 to +475
// Inject env vars into config.process.env so they are passed explicitly to
// the sandboxed child via the JSON config (not via process inheritance).
if (env) {
injectEnvIntoConfig(config, env);
}
@jsidewhite jsidewhite merged commit ef878d0 into main May 22, 2026
19 checks passed
@jsidewhite jsidewhite deleted the jsidewhite/env_from_sdk_to_cpis_pr branch May 22, 2026 16:20
@jsidewhite

Copy link
Copy Markdown
Member Author

Closes: #218

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants