Skip to content

[refac & fix] Simplify ProcessContainer selection & stop creating extra sandbox - #1285

Merged
Jeff Whiteside (jsidewhite) merged 1 commit into
mainfrom
jsidewhite/mxc_network_policy_helpers_RB
Sep 25, 2026
Merged

Jeff Whiteside (jsidewhite) merged 1 commit into
mainfrom
jsidewhite/mxc_network_policy_helpers_RB

Conversation

@jsidewhite

@jsidewhite Jeff Whiteside (jsidewhite) commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

For BaseContainer,

  1. Let's simplify choosing the Backend+Tier.
  2. Let's not make an extra sandbox.

The one decision point: can_backend_service_request

Decides if a backend for ProcessContainer can honor the ExecutionRequest very very clearly.

The one choice point: choose_backend_tier

Chooses a backend tier for ProcessContainer very very clearly.

Stop creating an extra Sandbox

Move to IsApiSetImplemented API-set availability checks instead of creating a real security environment.

Sandbox creation BEFORE

[20:38:02.591] [ETW] [wxc-exec.exe:28512] [VERB] CreateProcessSecurityEnvironment { PartA_PrivTags=16777216, wilActivity=<struct>, specificationSizeBytes=80, creationFlags=0, __TlgCV__="LUVr0eTj6U6O0Zp+Uw9rgA.0" }
[20:38:02.592] [ETW] [svchost.exe:15268] [VERB] SandboxEngineCreateSandbox { PartA_PrivTags=16777216, wilActivity=<struct>, identity="Sandbox.{FB9F31AD-93A0-4998-8157-4BCD705847F2}", sandboxSpecificationSize=80, __TlgCV__="LUVr0eTj6U6O0Zp+Uw9rgA.0" }
[20:38:02.592] [ETW] [svchost.exe:15268] [VERB] SandboxConfig { useAppContainer=1, integrityMode=0, integrityLevel=0, uiRestrictions=1023, useLeastPrivilege=0, readWritePathsCount=0, readOnlyPathsCount=0, capabilities="", PartA_PrivTags=16777216 }
[20:38:02.592] [ETW] [svchost.exe:15268] [VERB] SandboxNetworkFilteringPolicy { allowRuleCount=0, denyRuleCount=0, correlationVector="LUVr0eTj6U6O0Zp+Uw9rgA.0", PartA_PrivTags=16777216 }
[20:38:02.592] [ETW] [svchost.exe:15268] [VERB] SandboxEngineCreateSandbox { PartA_PrivTags=16777216, wilActivity=<struct> }
[20:38:02.592] [ETW] [wxc-exec.exe:28512] [VERB] CreateProcessSecurityEnvironment { PartA_PrivTags=16777216, wilActivity=<struct> }
[20:38:02.592] [ETW] [wxc-exec.exe:28512] [VERB] CreateProcessSecurityEnvironment { PartA_PrivTags=16777216, wilActivity=<struct>, specificationSizeBytes=120, creationFlags=0, __TlgCV__="f2rd+Rxwb0qkC9v/0SxE9A.0" }
[20:38:02.592] [ETW] [svchost.exe:15268] [VERB] SandboxEngineCreateSandbox { PartA_PrivTags=16777216, wilActivity=<struct>, identity="Sandbox.{5422A933-6DE7-4AA4-A63C-A78A0C02387C}", sandboxSpecificationSize=120, __TlgCV__="f2rd+Rxwb0qkC9v/0SxE9A.0" }
[20:38:02.592] [ETW] [svchost.exe:15268] [VERB] SandboxConfig { useAppContainer=1, integrityMode=0, integrityLevel=0, uiRestrictions=1023, useLeastPrivilege=0, readWritePathsCount=0, readOnlyPathsCount=0, capabilities="registryRead,learningModeLogging", PartA_PrivTags=16777216 }
[20:38:02.592] [ETW] [svchost.exe:15268] [VERB] SandboxNetworkFilteringPolicy { allowRuleCount=0, denyRuleCount=0, correlationVector="f2rd+Rxwb0qkC9v/0SxE9A.0", PartA_PrivTags=16777216 }
[20:38:02.593] [ETW] [svchost.exe:15268] [VERB] SandboxEngineCreateSandbox { PartA_PrivTags=16777216, wilActivity=<struct> }
[20:38:02.593] [ETW] [wxc-exec.exe:28512] [VERB] CreateProcessSecurityEnvironment { PartA_PrivTags=16777216, wilActivity=<struct> }

Sandbox creatin AFTER

[20:35:49.815] [ETW] [wxc-exec.exe:118872] [VERB] CreateProcessSecurityEnvironment { PartA_PrivTags=16777216, wilActivity=<struct>, specificationSizeBytes=120, creationFlags=0, __TlgCV__="umU1mU2ZBUOQpIdntwEw5A.0" }
[20:35:49.815] [ETW] [svchost.exe:15268] [VERB] SandboxEngineCreateSandbox { PartA_PrivTags=16777216, wilActivity=<struct>, identity="Sandbox.{6F45BD50-A15B-4EAA-BB3E-64ED55B561FE}", sandboxSpecificationSize=120, __TlgCV__="umU1mU2ZBUOQpIdntwEw5A.0" }
[20:35:49.815] [ETW] [svchost.exe:15268] [VERB] SandboxConfig { useAppContainer=1, integrityMode=0, integrityLevel=0, uiRestrictions=1023, useLeastPrivilege=0, readWritePathsCount=0, readOnlyPathsCount=0, capabilities="registryRead,learningModeLogging", PartA_PrivTags=16777216 }
[20:35:49.815] [ETW] [svchost.exe:15268] [VERB] SandboxNetworkFilteringPolicy { allowRuleCount=0, denyRuleCount=0, correlationVector="umU1mU2ZBUOQpIdntwEw5A.0", PartA_PrivTags=16777216 }
[20:35:49.816] [ETW] [svchost.exe:15268] [VERB] SandboxEngineCreateSandbox { PartA_PrivTags=16777216, wilActivity=<struct> }
[20:35:49.816] [ETW] [wxc-exec.exe:118872] [VERB] CreateProcessSecurityEnvironment { PartA_PrivTags=16777216, wilActivity=<struct> }

Refactor (delete)

..really this is just deleting the 7 extra "is_usable" duplicate checks for basecontainer availability.

Closes #1263

Microsoft Reviewers: Open in CodeFlow

Co-authored-by: Copilot <[email protected]>
Copilot-Session: c7101cd5-4604-4caf-a8be-7c140b26804c
Copilot AI balanced review requested due to automatic review settings September 25, 2026 20:24
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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.

Copilot review overview

🟡 Changes recommended

Obsolete duplicate probing and stale documentation remain, and one test can leak process-wide state after a panic.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity · 2 Low severity

Open (3)
What changed in this PR

Consolidates ProcessContainer backend selection and replaces sandbox-creating capability probes with Windows API-set checks.

Changes:

  • Centralizes request serviceability and tier selection.
  • Adds reusable API-set detection and refactors PSEC/Learning Mode handling.
  • Updates tests, examples, and ProcessContainer documentation.
File Description
src/​core/​wxc_common/​src/​lib.rs Exposes the Windows API-set module.
src/​core/​wxc_common/​src/​api_set.rs Adds the shared API-set probe.
src/​core/​wxc_common/​Cargo.toml Enables the required Windows API feature.
src/​core/​mxc_engine/​src/​run.rs Uses the consolidated dispatcher.
src/​core/​mxc_engine/​src/​probe.rs Uses read-only BaseContainer capability probes.
src/​core/​mxc_engine/​src/​guarded_capture.rs Simplifies capture-factory documentation and assertion.
src/​core/​mxc_engine/​src/​dispatch.rs Uses the consolidated streaming dispatcher.
src/​core/​learning_mode_platforms/​windows/​src/​lib.rs Exposes revised Learning Mode APIs and error classification.
src/​core/​learning_mode_platforms/​windows/​src/​ffi.rs Adds API-set gating and handle-owned stop operations.
src/​backends/​process_container/​common/​src/​test_env.rs Removes the deny-path test guard.
src/​backends/​process_container/​common/​src/​secenv.rs Centralizes typed PSEC capability and version queries.
src/​backends/​process_container/​common/​src/​probe.rs Uses the authoritative tier decision.
src/​backends/​process_container/​common/​src/​native_capture.rs Simplifies capture-session initialization.
src/​backends/​process_container/​common/​src/​guarded_capture.rs Updates dispatcher references.
src/​backends/​process_container/​common/​src/​fallback_detector.rs Consolidates tier selection around request serviceability.
src/​backends/​process_container/​common/​src/​dispatcher.rs Unifies capture-aware dispatch entry points.
src/​backends/​process_container/​common/​src/​base_container_runner.rs Implements authoritative BaseContainer serviceability checks.
src/​backends/​process_container/​common/​src/​base_container_helpers/​tests.rs Updates PSEC helper tests.
src/​backends/​process_container/​common/​src/​base_container_helpers.rs Refactors PSEC v1 specification construction.
src/​backends/​process_container/​common/​examples/​lm_probe.rs Updates probe documentation.
src/​backends/​process_container/​common/​examples/​lm_capture.rs Uses simplified capture-session startup.
docs/​process-container/​os-version-support.md Documents API-set-based selection.
docs/​process-container/​guide.md Documents centralized serviceability decisions.
docs/​backend-support-probe-api-plan.md Updates the BaseContainer probe description.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 368 to +378
let _lock = crate::test_env::lock();
// SAFETY: env-var mutation is serialized by the shared test lock.
unsafe {
std::env::set_var("MXC_FORCE_BC_USABLE", "1");
}
let request = ExecutionRequest::default();
let probes = test_probe_facts(false, false);

let selected = run_probe_with_capabilities(
&request,
probes,
request_capabilities(true, true, true),
false,
);
let selected = run_probe(&request, false);
// SAFETY: env-var mutation is serialized by the shared test lock.
unsafe {
std::env::remove_var("MXC_FORCE_BC_USABLE");
}
| Backend | How presence is detected today | Where | Risk with this method |
| --- | --- | --- | --- |
| `base-container` | `fallback_detector::is_base_container_usable()` loads `processmodel.dll`<br>and calls an OS capability/create API.<br>No process or VM launch; result cached in a `OnceLock`. | Rust | A cached result (`true` **or** `false`) can go stale if BaseContainer enablement<br>changes mid-process, and the probe is not perfectly pure since it loads a DLL. |
| `base-container` | `BaseContainerRunner::is_base_container_api_present()` calls `IsApiSetImplemented` for the process-security-environment API set. It does not load `processmodel.dll`, create a security environment, or start a process. | Rust | This proves that Windows implements the API-set contract; request-specific support bits are queried separately when the policy requires them. |
Comment on lines +282 to +286
pub(crate) fn choose_backend_tier(
request: &ExecutionRequest,
) -> Result<TierDecision, FallbackError> {
let policy = &request.policy;
let base_container_decision = BaseContainerRunner::can_backend_service_request(request);

/// Whether Windows implements the named API-set contract.
#[must_use]
pub fn is_api_set_implemented(name: &core::ffi::CStr) -> bool {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice

const STOP_NAME: &core::ffi::CStr = c"StopLearningModeTrace";
const CLOSE_NAME: &core::ffi::CStr = c"CloseLearningModeTrace";

/// Which Learning Mode trace exports resolved on this machine.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

jeff the code janitor 😊

@jsidewhite
Jeff Whiteside (jsidewhite) merged commit 20b3235 into main Sep 25, 2026
31 checks passed
@jsidewhite
Jeff Whiteside (jsidewhite) deleted the jsidewhite/mxc_network_policy_helpers_RB branch September 25, 2026 21:56
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.

BaseContainer creates a sandbox before the intended sandbox (even when probing)

3 participants