mxc-sdk 1.0.0

Importable library for starting MXC sandboxes in-process, with streaming stdio.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Run-to-completion backend selection and execution.
//!
//! This is the single home for "given an [`ExecutionRequest`], build the right
//! [`ScriptRunner`] and run it to completion." It centralizes the backend
//! `match` that previously lived inline in each executor binary (`wxc-exec`,
//! `lxc-exec`, `mxc-exec-mac`) so the binaries can shrink to thin CLI shells.
//!
//! Two entry points:
//!
//! - [`resolve_runner`] performs backend selection only, returning a
//!   [`ResolvedRunner`] (the boxed runner plus, on Windows, an optional
//!   [`DaclManager`](crate::mxc_common::filesystem_dacl::DaclManager) guard for the
//!   ProcessContainer fallback tiers, whose `Drop` restores host ACEs).
//!   Callers that must manage the guard's lifetime across signal / audit
//!   machinery (`wxc-exec`) use this and own the guard themselves.
//! - [`run`] is the convenience wrapper: resolve, run to completion, and drop
//!   the runner (then, on Windows, the guard) in the correct order. Callers
//!   without such machinery (`lxc-exec`, `mxc-exec-mac`, and the FFI layer) use
//!   this.
//!
//! Backend selection is per-host: the Windows body drives the ProcessContainer
//! fallback tiers plus the Windows experimental backends; the Linux body
//! mirrors `lxc-exec` (Bubblewrap / LXC / experimental); the macOS body always
//! resolves to Seatbelt.

use crate::mxc_common::logger::Logger;
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
use crate::mxc_common::models::ContainmentBackend;
use crate::mxc_common::models::{ExecutionRequest, ScriptResponse};
use crate::mxc_common::mxc_error::MxcError;
use crate::mxc_common::script_runner::ScriptRunner;

use crate::mxc_engine::error::Error;

/// A backend runner resolved for an [`ExecutionRequest`], ready to run.
///
/// On Windows, `dacl_manager` — when present — is the guard for the
/// ProcessContainer DACL-fallback tier: its `Drop` restores the host ACEs the
/// tier applied. It must outlive the run — drop the `runner` first, then the
/// manager (struct fields drop in declaration order, so `runner` is declared
/// first). Callers that hand the manager off to external cleanup machinery
/// (`wxc-exec` parks it for its Ctrl-C handler) take it out of the struct.
pub struct ResolvedRunner {
    /// The boxed run-to-completion runner for the selected backend.
    pub runner: Box<dyn ScriptRunner>,
    /// Guard restoring host ACEs applied by the ProcessContainer DACL-fallback
    /// tier; `None` for every other tier and backend. Windows only.
    #[cfg(target_os = "windows")]
    pub dacl_manager: Option<crate::mxc_common::filesystem_dacl::DaclManager>,
}

impl ResolvedRunner {
    /// Wrap a runner that needs no DACL guard.
    #[cfg(target_os = "windows")]
    fn without_guard(runner: Box<dyn ScriptRunner>) -> Self {
        Self {
            runner,
            dacl_manager: None,
        }
    }

    /// Wrap a runner (non-Windows hosts have no DACL guard).
    #[cfg(not(target_os = "windows"))]
    fn without_guard(runner: Box<dyn ScriptRunner>) -> Self {
        Self { runner }
    }
}

/// Select the containment backend for `request` and construct its
/// run-to-completion [`ScriptRunner`].
///
/// On Windows the ProcessContainer backend drives
/// [`dispatch_with_fallback`](crate::process_container_common::dispatcher::dispatch_with_fallback),
/// logging the selected isolation tier and any tier-selection warnings to
/// `logger`, and surfacing the DACL guard in the returned [`ResolvedRunner`].
///
/// Experimental backends, classified by the engine's backend registry, require
/// `request.experimental_enabled`; without it they return a
/// [`backend_unavailable`](MxcError::backend_unavailable) error before any
/// host-specific resolution. Backends that are not available on this host /
/// not compiled in return an
/// [`unsupported_containment`](MxcError::unsupported_containment) error.
pub fn resolve_runner(
    request: &ExecutionRequest,
    logger: &mut Logger,
) -> Result<ResolvedRunner, Error> {
    log_policy_hash(request, logger);
    crate::mxc_engine::experimental::require_experimental_optin(
        &request.containment,
        request.experimental_enabled,
    )?;
    #[cfg(target_os = "windows")]
    {
        resolve_runner_inner_windows(request, logger).map_err(Error::from)
    }
    #[cfg(not(target_os = "windows"))]
    resolve_runner_inner(request, logger).map_err(Error::from)
}

/// Record `mxc.PolicyHash`: the canonical identity of the effective policy this
/// run is about to be launched under, plus the config schema version.
pub fn log_policy_hash(request: &ExecutionRequest, logger: &mut Logger) {
    use crate::mxc_common::audit::{AuditEvent, AuditEventName};

    if !logger.has_diagnostic_sink() && !crate::mxc_common::telemetry::is_active() {
        return;
    }

    let policy_hash = crate::mxc_common::policy_identity::policy_hash(request);
    let config_schema_version = config_schema_version(request);
    if crate::mxc_common::telemetry::is_active() {
        let identity = policy_hash_identity(&request.container_id);
        crate::mxc_common::telemetry::log_policy_hash(
            &identity,
            &policy_hash,
            config_schema_version,
        );
    }
    let record = AuditEvent::new(AuditEventName::PolicyHash)
        .str("backend", request.containment.wire_name())
        .str("policy_hash", &policy_hash)
        .str("config_schema_version", config_schema_version);
    logger.log_audit_event(&record);
}

fn config_schema_version(request: &ExecutionRequest) -> &'static str {
    request.source_contract_version()
}

fn policy_hash_identity(container_id: &str) -> String {
    let identity = if container_id.is_empty() {
        "CLI"
    } else {
        container_id
    };
    crate::mxc_common::policy_identity::redact_identity(identity)
}

#[cfg(test)]
mod attribution_tests {
    use super::config_schema_version;
    use crate::mxc_common::logger::{Logger, Mode};
    use crate::mxc_common::models::{ExecutionRequest, NetworkEnforcementCompatibility};
    use crate::mxc_common::state_aware_request::MxcRequest;

    #[test]
    fn telemetry_attributes_exact_json_but_not_typed_sdk_requests() {
        let mut logger = Logger::new(Mode::Buffer);
        let parsed = crate::mxc_common::config_parser::load_mxc_request_from_json(
            r#"{
                "version": "0.9.0-alpha",
                "process": {"commandLine": "echo exact"}
            }"#,
            &mut logger,
        )
        .unwrap();
        let MxcRequest::OneShot(exact) = parsed else {
            panic!("expected one-shot request");
        };
        assert_eq!(config_schema_version(&exact), "0.9.0-alpha");
        assert_eq!(
            exact.network_enforcement_compatibility,
            NetworkEnforcementCompatibility::Strict
        );

        let direct = ExecutionRequest {
            script_code: "echo direct".to_string(),
            ..ExecutionRequest::default()
        };
        assert_eq!(config_schema_version(&direct), "");
        assert_eq!(direct.source_contract, None);
        assert_eq!(
            direct.network_enforcement_compatibility,
            NetworkEnforcementCompatibility::Strict
        );
    }
}

/// Resolve a runner for the `wxc-exec --audit` compatibility workflow, applying
/// the same experimental-backend check as [`resolve_runner`].
#[cfg(target_os = "windows")]
pub fn resolve_runner_for_audit(
    request: &ExecutionRequest,
    logger: &mut Logger,
) -> Result<ResolvedRunner, Error> {
    crate::mxc_engine::experimental::require_experimental_optin(
        &request.containment,
        request.experimental_enabled,
    )?;
    resolve_runner_inner_windows(request, logger).map_err(Error::from)
}

/// Resolve `request`'s backend and run it to completion.
///
/// Convenience over [`resolve_runner`] for callers without external guard /
/// signal machinery: it runs the resolved runner and drops it — then, on
/// Windows, the DACL guard — in the correct order before returning the
/// [`ScriptResponse`].
pub fn run(request: &ExecutionRequest, logger: &mut Logger) -> Result<ScriptResponse, Error> {
    let mut resolved = resolve_runner(request, logger)?;
    let response = resolved.runner.run(request, logger);
    // `resolved` drops here: `runner` first (releasing child handles), then —
    // on Windows — `dacl_manager` (restoring host ACEs).
    Ok(response)
}

// ---------------------------------------------------------------------------
// Windows: ProcessContainer fallback tiers + Windows experimental backends.
// ---------------------------------------------------------------------------

#[cfg(target_os = "windows")]
fn resolve_runner_inner_windows(
    request: &ExecutionRequest,
    logger: &mut Logger,
) -> Result<ResolvedRunner, MxcError> {
    use std::fmt::Write;

    match request.containment {
        ContainmentBackend::ProcessContainer => {
            // ProcessContainer resolves to a concrete Windows backend purely by
            // host capability: `dispatch_with_fallback` prefers
            // the native BaseContainer (OS sandbox API) when usable and
            // otherwise falls back to AppContainer tiers (BFS / DACL). The
            // schema version does not influence this choice. When the request
            // sets `captureDenials`, `factory_for_request` hands the guarded
            // WPR fallback factory to the dispatcher so an AppContainer
            // fallback tier can still honor it instead of failing closed.
            let capture_factory = crate::mxc_engine::guarded_capture::factory_for_request(request);

            match crate::process_container_common::dispatcher::dispatch_with_fallback(
                request,
                capture_factory,
            ) {
                Ok(dispatched) => {
                    for w in &dispatched.warnings {
                        let _ = writeln!(logger, "warning: {w}");
                    }
                    let _ = writeln!(
                        logger,
                        "selected isolation tier: {}",
                        dispatched.tier.as_str()
                    );
                    dispatched.log_enforcement_degraded(logger);
                    let (runner, dacl_manager) = dispatched.into_runner_and_guard();
                    Ok(ResolvedRunner {
                        runner,
                        dacl_manager,
                    })
                }
                Err(e) => {
                    // Surface any retained-entry DACL warnings through the
                    // logger so the caller's buffer flush still reports them.
                    if let crate::process_container_common::dispatcher::DispatchError::Dacl {
                        warnings,
                        ..
                    } = &e
                    {
                        for w in warnings {
                            let _ = writeln!(logger, "dacl warning: {w}");
                        }
                    }
                    Err(MxcError::backend_unavailable(format!("{e}")))
                }
            }
        }
        ContainmentBackend::Wslc => {
            #[cfg(feature = "wslc")]
            {
                let _ = writeln!(logger, "Using WSLContainer runner");
                let wslc_config = request.wslc.as_ref().cloned().unwrap_or_default();
                Ok(ResolvedRunner::without_guard(Box::new(
                    crate::wslc_common::wsl_container_runner::WSLContainerRunner::new(&wslc_config),
                )))
            }
            #[cfg(not(feature = "wslc"))]
            {
                let _ = logger;
                Err(MxcError::unsupported_containment(
                    "WSLC backend not compiled. Rebuild with --features wslc.",
                ))
            }
        }
        ContainmentBackend::Lxc => Err(MxcError::unsupported_containment(
            "LXC backend not available on Windows",
        )),
        ContainmentBackend::Bubblewrap => Err(MxcError::unsupported_containment(
            "Bubblewrap backend not available on Windows",
        )),
        ContainmentBackend::Seatbelt => Err(MxcError::unsupported_containment(
            "Seatbelt backend is only available on macOS (use mxc-exec-mac)",
        )),
        ContainmentBackend::Vm => Err(MxcError::unsupported_containment(
            "VM backend not yet implemented",
        )),
        ContainmentBackend::MicroVm => {
            #[cfg(feature = "microvm")]
            {
                Ok(ResolvedRunner::without_guard(Box::new(
                    crate::nanvix_runner::NanVixScriptRunner::new(),
                )))
            }
            #[cfg(not(feature = "microvm"))]
            {
                Err(MxcError::unsupported_containment(
                    "MicroVM backend not compiled in (build with --features microvm)",
                ))
            }
        }
        ContainmentBackend::Hyperlight => resolve_hyperlight(),
        ContainmentBackend::WindowsSandbox => {
            if let Some(ws) = &request.windows_sandbox {
                let default = crate::mxc_common::models::WindowsSandboxConfig::default();
                if ws.idle_timeout_ms != default.idle_timeout_ms
                    || ws.daemon_pipe_name != default.daemon_pipe_name
                {
                    let _ = writeln!(
                        logger,
                        "warning: windowsSandbox.idleTimeoutMs and daemonPipeName \
                         are ignored by the one-shot backend; each invocation launches and tears \
                         down a fresh VM"
                    );
                }
            }
            Ok(ResolvedRunner::without_guard(Box::new(
                crate::windows_sandbox_lifecycle::WindowsSandboxRunner::new(),
            )))
        }
        ContainmentBackend::IsolationSession => {
            #[cfg(feature = "isolation_session")]
            {
                Ok(ResolvedRunner::without_guard(Box::new(
                    crate::isolation_session_common::IsolationSessionRunner::new(),
                )))
            }
            #[cfg(not(feature = "isolation_session"))]
            {
                Err(MxcError::unsupported_containment(
                    "IsolationSession backend not compiled. Rebuild with --features isolation_session.",
                ))
            }
        }
    }
}

// ---------------------------------------------------------------------------
// Linux: Bubblewrap, LXC, and the experimental Hyperlight / MicroVM backends.
// A concrete backend selected for another host must fail closed.
// ---------------------------------------------------------------------------

#[cfg(target_os = "linux")]
fn resolve_runner_inner(
    request: &ExecutionRequest,
    _logger: &mut Logger,
) -> Result<ResolvedRunner, MxcError> {
    use crate::mxc_common::sandbox_process::Runner;

    match request.containment {
        ContainmentBackend::Hyperlight => resolve_hyperlight(),
        ContainmentBackend::MicroVm => {
            #[cfg(feature = "microvm")]
            {
                Ok(ResolvedRunner::without_guard(Box::new(
                    crate::nanvix_runner::NanVixScriptRunner::new(),
                )))
            }
            #[cfg(not(feature = "microvm"))]
            {
                Err(MxcError::unsupported_containment(
                    "MicroVM backend not compiled in (build with --features microvm)",
                ))
            }
        }
        ContainmentBackend::Bubblewrap => Ok(ResolvedRunner::without_guard(Box::new(Runner::new(
            crate::bwrap_common::bwrap_runner::BubblewrapScriptRunner::new(),
        )))),
        ContainmentBackend::Lxc => Ok(ResolvedRunner::without_guard(Box::new(
            crate::lxc_common::lxc_runner::LxcScriptRunner::new(
                &request.lxc_config,
                &request.container_id,
                &request.lifecycle,
            ),
        ))),
        ref other => Err(MxcError::unsupported_containment(format!(
            "the '{}' backend is not available on Linux",
            other.wire_name()
        ))),
    }
}

// ---------------------------------------------------------------------------
// macOS: Seatbelt only. A concrete backend selected for another host must fail
// closed rather than silently weakening or changing the requested containment.
// ---------------------------------------------------------------------------

#[cfg(target_os = "macos")]
fn resolve_runner_inner(
    request: &ExecutionRequest,
    _logger: &mut Logger,
) -> Result<ResolvedRunner, MxcError> {
    use crate::mxc_common::sandbox_process::Runner;

    if request.containment != ContainmentBackend::Seatbelt {
        return Err(MxcError::unsupported_containment(format!(
            "the '{}' backend is not available on macOS",
            request.containment.wire_name()
        )));
    }
    Ok(ResolvedRunner::without_guard(Box::new(Runner::new(
        crate::seatbelt_common::seatbelt_runner::SeatbeltScriptRunner::new(),
    ))))
}

#[cfg(all(test, target_os = "linux"))]
mod linux_tests {
    use super::*;
    use crate::mxc_common::logger::Mode;

    #[test]
    fn cross_platform_backend_is_rejected_instead_of_falling_back_to_lxc() {
        let request = ExecutionRequest {
            containment: ContainmentBackend::Seatbelt,
            ..Default::default()
        };
        let mut logger = Logger::new(Mode::Buffer);

        let error = match resolve_runner_inner(&request, &mut logger) {
            Ok(_) => panic!("Seatbelt must not fall back to LXC on Linux"),
            Err(error) => error,
        };

        assert_eq!(
            error.code,
            crate::mxc_common::mxc_error::MxcErrorCode::UnsupportedContainment
        );
        assert!(error.message.contains("seatbelt"));
    }
}

#[cfg(all(test, target_os = "macos"))]
mod macos_tests {
    use super::*;
    use crate::mxc_common::logger::Mode;

    #[test]
    fn cross_platform_backend_is_rejected_instead_of_falling_back_to_seatbelt() {
        let request = ExecutionRequest {
            containment: ContainmentBackend::Lxc,
            ..Default::default()
        };
        let mut logger = Logger::new(Mode::Buffer);

        let error = match resolve_runner_inner(&request, &mut logger) {
            Ok(_) => panic!("LXC must not fall back to Seatbelt on macOS"),
            Err(error) => error,
        };

        assert_eq!(
            error.code,
            crate::mxc_common::mxc_error::MxcErrorCode::UnsupportedContainment
        );
        assert!(error.message.contains("lxc"));
    }
}

// ---------------------------------------------------------------------------
// Any other host: no backend.
// ---------------------------------------------------------------------------

#[cfg(not(any(target_os = "windows", target_os = "linux", target_os = "macos")))]
fn resolve_runner_inner(
    _request: &ExecutionRequest,
    _logger: &mut Logger,
) -> Result<ResolvedRunner, MxcError> {
    Err(MxcError::unsupported_containment(
        "the mxc engine has no run-to-completion backend for this host OS \
         (supported: Windows, Linux, macOS)",
    ))
}

/// Construct the Hyperlight runner, shared by the Windows and Linux bodies.
/// Requires x86_64 (Hyperlight needs KVM or WHP) and the `hyperlight` feature.
/// On Windows, pre-checks that `winhvplatform.dll` is loadable so a missing
/// WHP becomes a typed error rather than a delay-load SEH exception; on
/// Linux, that `/dev/kvm` opens for reading and writing, for the same reason.
#[cfg(any(target_os = "windows", target_os = "linux"))]
fn resolve_hyperlight() -> Result<ResolvedRunner, MxcError> {
    #[cfg(all(feature = "hyperlight", target_arch = "x86_64"))]
    {
        // WHP is delay-loaded; check before setup boots a VM.
        #[cfg(target_os = "windows")]
        if !crate::hyperlight_common::is_whp_available() {
            return Err(MxcError::backend_unavailable(
                "Hyperlight requires Windows Hypervisor Platform (WHP). \
                 Enable the HypervisorPlatform Windows optional feature and reboot.",
            ));
        }
        // KVM is checked before a run boots a VM, as WHP is on Windows.
        #[cfg(target_os = "linux")]
        if !crate::hyperlight_common::is_kvm_available() {
            return Err(MxcError::backend_unavailable(
                "Hyperlight requires KVM: /dev/kvm must be readable and writable by this user.",
            ));
        }
        Ok(ResolvedRunner::without_guard(Box::new(
            crate::hyperlight_common::HyperlightScriptRunner::new(),
        )))
    }
    #[cfg(not(all(feature = "hyperlight", target_arch = "x86_64")))]
    {
        Err(MxcError::unsupported_containment(
            "Hyperlight backend requires x86_64 (Hyperlight needs KVM or WHP)",
        ))
    }
}

#[cfg(all(test, target_os = "windows"))]
mod tests {
    use super::*;
    use crate::mxc_common::logger::Mode;
    use crate::mxc_common::models::WindowsSandboxConfig;

    fn windows_sandbox_request(config: Option<WindowsSandboxConfig>) -> ExecutionRequest {
        ExecutionRequest {
            containment: ContainmentBackend::WindowsSandbox,
            experimental_enabled: true,
            windows_sandbox: config,
            ..Default::default()
        }
    }

    #[test]
    fn policy_hash_identity_matches_runner_identity_rules() {
        assert_eq!(policy_hash_identity(""), "CLI");
        assert_eq!(
            policy_hash_identity("sandbox-0123456789abcdef"),
            "sandbox-0123456789abcdef"
        );
        assert_eq!(policy_hash_identity("alice@example.com"), "entra-upn");
        assert_eq!(policy_hash_identity("arbitrary identity"), "redacted");
    }

    /// Both one-shot resolution paths refuse every experimental backend without
    /// the opt-in, with the same code the state-aware dispatcher uses, before
    /// any host-specific check.
    #[test]
    fn experimental_backends_require_the_optin_on_both_resolution_paths() {
        type Resolve = fn(&ExecutionRequest, &mut Logger) -> Result<ResolvedRunner, Error>;

        for containment in [
            ContainmentBackend::WindowsSandbox,
            ContainmentBackend::MicroVm,
            ContainmentBackend::Hyperlight,
        ] {
            let request = ExecutionRequest {
                containment,
                ..Default::default()
            };
            let resolvers: [Resolve; 2] = [resolve_runner, resolve_runner_for_audit];
            for resolve in resolvers {
                let mut logger = Logger::new(Mode::Buffer);
                let error = match resolve(&request, &mut logger) {
                    Ok(_) => panic!("{:?} must require the opt-in", request.containment),
                    Err(error) => error,
                };
                assert_eq!(error.code, crate::ErrorCode::BackendUnavailable);
                assert!(error.message.contains("experimental"), "{error}");
            }
        }
    }

    #[test]
    fn windows_sandbox_default_settings_do_not_warn() {
        for config in [None, Some(WindowsSandboxConfig::default())] {
            let request = windows_sandbox_request(config);
            let mut logger = Logger::new(Mode::Buffer);
            resolve_runner_inner_windows(&request, &mut logger).unwrap();
            assert!(logger.get_buffer().is_empty());
        }
    }

    #[test]
    fn windows_sandbox_non_default_legacy_settings_warn() {
        let config = WindowsSandboxConfig {
            idle_timeout_ms: 1,
            ..Default::default()
        };
        let request = windows_sandbox_request(Some(config));
        let mut logger = Logger::new(Mode::Buffer);

        resolve_runner_inner_windows(&request, &mut logger).unwrap();

        let warning = logger.get_buffer();
        assert!(warning.contains("idleTimeoutMs"));
        assert!(warning.contains("daemonPipeName"));
        assert!(warning.contains("fresh VM"));
    }

    #[cfg(feature = "wslc")]
    #[test]
    fn wslc_resolves_without_experimental_optin() {
        let request = ExecutionRequest {
            containment: ContainmentBackend::Wslc,
            ..Default::default()
        };
        let mut logger = Logger::new(Mode::Buffer);

        resolve_runner_inner_windows(&request, &mut logger)
            .expect("WSLC selection must not require runtime experimental authorization");

        assert!(!logger.get_buffer().contains("experimental"));
    }
}