mxc-sdk 1.2.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
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! Reusable configuration DTOs shared by exact-contract adapters and typed SDK
//! builders. These are normalization inputs, not an externally deserializable
//! whole-request contract.

use serde::Serialize;

/// State-aware lifecycle phase.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Phase {
    Provision,
    Start,
    Exec,
    Stop,
    Deprovision,
}

/// Containment backend (abstract intent or concrete backend).
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum Containment {
    /// OS-native process sandbox (resolved per host).
    Process,
    /// Windows native ProcessContainer (PSEC).
    #[serde(rename = "processcontainer", alias = "appcontainer")]
    ProcessContainer,
    /// VM-class isolation (resolved per host).
    Vm,
    /// Windows Sandbox (experimental).
    WindowsSandbox,
    /// Full Linux container.
    Lxc,
    /// NanVix micro-VM (experimental).
    Microvm,
    /// Hyperlight micro-VM (experimental).
    Hyperlight,
    /// WSL container.
    Wslc,
    /// macOS Seatbelt.
    #[serde(alias = "macos_sandbox")]
    Seatbelt,
    /// Windows IsolationSession.
    IsolationSession,
    /// Unprivileged Linux bubblewrap sandbox.
    Bubblewrap,
    /// Remote Windows 365 container lifecycle operations (experimental).
    W365Agents,
}

impl Containment {
    pub(crate) fn parse_wire_name(value: &str) -> Option<Self> {
        Some(match value {
            "process" => Self::Process,
            "processcontainer" | "appcontainer" => Self::ProcessContainer,
            "vm" => Self::Vm,
            "windows_sandbox" => Self::WindowsSandbox,
            "lxc" => Self::Lxc,
            "microvm" => Self::Microvm,
            "hyperlight" => Self::Hyperlight,
            "wslc" => Self::Wslc,
            "seatbelt" | "macos_sandbox" => Self::Seatbelt,
            "isolation_session" => Self::IsolationSession,
            "bubblewrap" => Self::Bubblewrap,
            "w365_agents" => Self::W365Agents,
            _ => return None,
        })
    }
}

/// Process execution settings.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Process {
    /// Command line (or script) to execute.
    pub command_line: Option<String>,
    /// Working directory for the process. When omitted, backends substitute a
    /// directory the sandbox can use rather than inheriting the launcher's cwd:
    /// Windows ProcessContainer picks the first `readwritePaths` entry that is
    /// an existing directory, else the first such `readonlyPaths` entry, else
    /// the system drive root; Seatbelt applies the same precedence with a `/`
    /// fallback; LXC/WSL use the container root; NanVix and Hyperlight reject a
    /// working directory outright. See `docs/schema.md` ("Working Directory").
    pub cwd: Option<String>,
    /// Environment variables as `"KEY=VALUE"` strings.
    ///
    /// Omit the field to give the child the backend's default environment (on
    /// Windows, the user's profile block). Supply it — including as an empty
    /// array — and it is used verbatim; MXC adds nothing to it unless
    /// `inheritDefaultEnv` is set.
    pub env: Option<Vec<String>>,
    /// Start from the backend's default environment and layer `env` on top of
    /// it, rather than replacing it (default false).
    ///
    /// This exists because the default environment is not something a caller
    /// can assemble: on Windows it is the user's profile block, which only the
    /// OS can produce. Entries in `env` override same-named defaults. Has no
    /// effect on backends whose default environment is empty, and none when
    /// `env` is omitted (that already yields the default).
    pub inherit_default_env: Option<bool>,
    /// Wall-clock timeout in milliseconds.
    pub timeout: Option<u32>,
}

/// Container lifecycle settings.
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Lifecycle {
    /// Destroy the container when the process exits (default true).
    pub destroy_on_exit: Option<bool>,
    /// Preserve the applied policy after exit (default false).
    pub preserve_policy: Option<bool>,
}

/// ProcessContainer-specific settings.
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ProcessContainer {
    /// Enforce least-privilege mode.
    pub least_privilege: Option<bool>,
    /// AppContainer learning mode (deny-and-record): failed access checks are
    /// logged for diagnostics while the accesses stay denied; containment is
    /// unchanged. Distinct from the allow-all `permissiveLearningMode`
    /// capability, which is injected internally by the `--audit` CLI flag or
    /// dedicated denial-capture configuration.
    pub learning_mode: Option<bool>,
    /// AppContainer capabilities (e.g. `internetClient`, `registryRead`).
    /// Each array entry must contain exactly one capability name; commas are
    /// rejected because BaseContainer uses commas as its wire delimiter.
    /// `learningModeLogging` and `permissiveLearningMode` are reserved and
    /// rejected here; use `learningMode`, `--audit`, or the dedicated denial
    /// capture configuration instead.
    pub capabilities: Option<Vec<String>>,
    /// Windows denial capture. When present, the runner records the sandboxed
    /// process's access attempts to a learning-mode ETL trace for later
    /// inspection. MXC prefers native PSEC plus V2 Learning Mode when that API
    /// set can fully honor the request. Otherwise it retains the highest
    /// compatible containment tier and uses guarded WPR capture, so
    /// `leastPrivilege` and deny-path policies remain enforced.
    pub capture_denials: Option<CaptureDenials>,
    /// BaseProcessContainer UI settings (Windows).
    pub ui: Option<BaseProcessUi>,
    /// ProcessContainer-specific filesystem configuration.
    pub filesystem: Option<ProcessContainerFilesystem>,
    /// ProcessContainer-specific network configuration.
    pub network: Option<ProcessContainerNetwork>,
}

/// ProcessContainer-specific filesystem configuration.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ProcessContainerFilesystem {
    /// Paths the process can query or enumerate without reading file contents.
    pub enumerate_paths: Option<Vec<String>>,
}

/// ProcessContainer-specific network configuration.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct ProcessContainerNetwork {
    /// Installed package family name or AppContainer profile allowed to host
    /// the configured loopback proxy.
    pub allowed_proxy_peer: Option<String>,
}

/// Windows denial-capture settings. The presence of the `captureDenials`
/// object enables capture; all fields are optional. Native capture requires
/// the complete compatible PSEC plus V2 Learning Mode API set. Requests that
/// native capture cannot represent use guarded WPR with a compatible
/// AppContainer containment tier.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct CaptureDenials {
    /// How each ungranted access check is handled while it is recorded. Both
    /// modes log every access the policy does not grant to the ETL trace; the
    /// mode only decides whether that access is blocked or allowed. Defaults to
    /// `block` when omitted.
    pub mode: Option<CaptureDenialsMode>,
    /// Absolute path where the JSON denials output file is written — the
    /// deliverable a consuming application reads to learn what the workload
    /// was denied. It is a single JSON document `{ "denials": [...],
    /// "summary": {...} }`. A per-run identifier (process id plus random
    /// suffix) is inserted into the file stem (e.g. `denials.json` ->
    /// `denials.<run-id>.json`) so concurrent and sequential captures do not
    /// collide; the actual path is reported on stderr. When omitted, MXC
    /// writes it to a managed per-run temporary file and prints its path on
    /// stderr. The parent directory must already exist. (The intermediate ETL
    /// trace is an internal, runner-managed file in a protected per-run
    /// directory. Retained traces use
    /// `%LOCALAPPDATA%\Microsoft\MXC\capture-denials\retained`; non-retained
    /// traces use the system temporary directory.)
    pub output_path: Option<String>,
    /// Keep the sealed ETL trace after analysis and report its path in output
    /// metadata. Defaults to `false`, which deletes the trace after analysis.
    /// Retention requires a terminal wait; abandoning the process handle
    /// deletes the internal trace. If post-seal analysis fails, the failure and
    /// retained path are exposed through `captureDenialsError` output metadata.
    /// Retained traces can contain sensitive resource paths and identifiers.
    /// When any later capture starts, MXC tries to delete retained traces that
    /// are 7 or more days old; move a trace elsewhere to keep it longer.
    pub retain_etl: Option<bool>,
}

/// How `captureDenials` handles each ungranted access check while recording it.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum CaptureDenialsMode {
    /// `block` — the access stays **denied** and the denial is recorded.
    /// Deny-by-default containment is preserved; this is the safe default.
    Block,
    /// `allow` — the access is **allowed** and recorded (audit mode).
    /// This relaxes deny-by-default for the run, so it is a security-sensitive
    /// choice and the runner emits a security warning.
    Allow,
}

/// BaseProcessContainer UI isolation settings.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct BaseProcessUi {
    /// UI isolation level.
    pub isolation: Option<UiIsolation>,
    /// Whether desktop system control is allowed.
    pub desktop_system_control: Option<bool>,
    /// System settings access level.
    pub system_settings: Option<UiSystemSettings>,
    /// Whether the IME (Input Method Editor) is allowed.
    pub ime: Option<bool>,
}

/// Desktop UI isolation level.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum UiIsolation {
    Desktop,
    Handles,
    Atoms,
    Container,
}

impl UiIsolation {
    /// Lowercase wire-format string matching the schema enum values.
    pub fn as_str(&self) -> &'static str {
        match self {
            UiIsolation::Desktop => "desktop",
            UiIsolation::Handles => "handles",
            UiIsolation::Atoms => "atoms",
            UiIsolation::Container => "container",
        }
    }
}

/// Desktop UI system settings access level.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum UiSystemSettings {
    None,
    Parameters,
    Display,
    All,
}

impl UiSystemSettings {
    /// Lowercase wire-format string matching the schema enum values.
    pub fn as_str(&self) -> &'static str {
        match self {
            UiSystemSettings::None => "none",
            UiSystemSettings::Parameters => "parameters",
            UiSystemSettings::Display => "display",
            UiSystemSettings::All => "all",
        }
    }
}

/// LXC container settings.
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Lxc {
    /// Distribution image (e.g. `alpine`).
    pub distribution: Option<String>,
    /// Distribution release (e.g. `3.23`).
    pub release: Option<String>,
}

/// Filesystem access policy.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Filesystem {
    /// Paths the process can read and write.
    pub readwrite_paths: Option<Vec<String>>,
    /// Paths the process can read but not write.
    pub readonly_paths: Option<Vec<String>>,
    /// Paths explicitly denied (override broader allow rules).
    pub denied_paths: Option<Vec<String>>,
}

/// Network access policy.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Network {
    /// Outbound network policy.
    pub egress: Option<NetworkEgress>,
    /// Inbound and host-loopback network policy.
    pub ingress: Option<NetworkIngress>,
}

/// Outbound network policy.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct NetworkEgress {
    /// Action used when no explicit rule matches. Defaults to `deny`.
    pub default: Option<NetworkAction>,
    /// Explicit allow rules.
    pub allow: Option<Vec<NetworkRule>>,
    /// Explicit deny rules. Deny rules take precedence over allow rules.
    pub deny: Option<Vec<NetworkRule>>,
}

/// Inbound and host-loopback network policy.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct NetworkIngress {
    /// Default action for LAN/private-network inbound traffic.
    pub default: Option<NetworkAction>,
    /// Bidirectional host-loopback connectivity action.
    pub host_loopback: Option<NetworkAction>,
}

/// Allow or deny network action.
#[derive(Debug, Clone, Copy, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum NetworkAction {
    Allow,
    Deny,
}

/// Outbound network rule.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct NetworkRule {
    /// Destination CIDRs. Omission matches both IP families.
    pub to: Option<Vec<NetworkPeer>>,
    /// Destination protocols and ports. Omission matches all.
    pub ports: Option<Vec<NetworkPort>>,
}

/// CIDR network peer.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct NetworkPeer {
    /// IPv4 or IPv6 CIDR.
    pub cidr: String,
    /// CIDRs excluded from this peer.
    pub except: Option<Vec<String>>,
}

/// Protocol and destination-port selector.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct NetworkPort {
    /// Transport protocol. Defaults to `any`.
    pub protocol: Option<NetworkProtocol>,
    /// Destination port. Omission matches every port.
    pub port: Option<u16>,
    /// Inclusive end of a destination-port range. Requires `port`.
    pub end_port: Option<u16>,
}

/// Transport protocol selector.
#[derive(Debug, Clone, Copy, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum NetworkProtocol {
    Tcp,
    Udp,
    Icmp,
    Any,
}

/// Runtime values supplied alongside, but separate from, sandbox policy.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct RuntimeConfig {
    /// HTTP/S loopback proxy URL.
    pub network_proxy: Option<String>,
}

/// Cross-platform UI isolation policy.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Ui {
    /// Disable all UI access (default true).
    pub disable: Option<bool>,
    /// Clipboard access level.
    pub clipboard: Option<ClipboardPolicy>,
    /// Allow UI injection.
    pub injection: Option<bool>,
}

/// Clipboard access level.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum ClipboardPolicy {
    None,
    Read,
    Write,
    All,
}

/// macOS Seatbelt backend configuration.
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Seatbelt {
    /// Replace the generated profile entirely (advanced/testing escape hatch).
    pub profile_override: Option<String>,
    /// Allow GUI (WindowServer) access.
    pub gui_access: Option<bool>,
    /// Attach the inner process to a nested pty (default true).
    pub nested_pty: Option<bool>,
    /// Allow Keychain access.
    pub keychain_access: Option<bool>,
    /// Additional Mach service global-names the inner process may resolve.
    pub extra_mach_lookups: Option<Vec<String>>,
    /// IOKit user-client class rules (development contract only).
    pub custom_io_kits: Option<SeatbeltCustomRules>,
    /// Mach registration rules (development contract only).
    pub custom_mach_registers: Option<SeatbeltCustomMachRegisters>,
    /// Mach lookup rules (development contract only).
    pub custom_mach_lookups: Option<SeatbeltCustomRules>,
    /// POSIX shared memory rules (development contract only).
    pub custom_posix_shm: Option<SeatbeltCustomPosixShm>,
    /// Seatbelt denial capture (development contract only).
    pub capture_denials: Option<SeatbeltCaptureDenials>,
}

/// Access for names that no Seatbelt custom rule entry matches.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum SeatbeltCustomDefault {
    Allow,
    Deny,
}

/// Seatbelt allow and deny lists for one kind of name.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SeatbeltCustomRules {
    /// Defaults to `deny` when omitted.
    pub default: Option<SeatbeltCustomDefault>,
    pub allow: Option<Vec<String>>,
    pub deny: Option<Vec<String>>,
}

/// Seatbelt Mach registration rules, by name scope.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SeatbeltCustomMachRegisters {
    pub global: Option<SeatbeltCustomRules>,
    pub local: Option<SeatbeltCustomRules>,
}

/// Access to a Seatbelt POSIX shared memory name.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum SeatbeltPosixShmAccess {
    Deny,
    Read,
    ReadWrite,
    Create,
    Own,
}

/// Seatbelt POSIX shared memory rules, by access.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SeatbeltCustomPosixShm {
    /// Defaults to `deny` when omitted.
    pub default: Option<SeatbeltPosixShmAccess>,
    pub read: Option<Vec<String>>,
    pub read_write: Option<Vec<String>>,
    pub create: Option<Vec<String>>,
    pub own: Option<Vec<String>>,
    pub deny: Option<Vec<String>>,
}

/// macOS Seatbelt denial-capture settings.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SeatbeltCaptureDenials {
    /// Defaults to `block` when omitted.
    pub mode: Option<CaptureDenialsMode>,
    /// Absolute path for the JSON denials report; a run id is inserted into
    /// the file stem. Its parent directory must exist.
    pub output_path: Option<String>,
    /// Keep the raw `log stream` trace next to the report. Defaults to `false`.
    pub retain_etl: Option<bool>,
}

/// Telemetry configuration (`telemetry`).
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Telemetry {
    /// Explicit telemetry opt-in for this invocation. `true` = opt in (still
    /// subject to the user's consent and to administrative policy — it can
    /// never turn telemetry on for someone who has not consented), `false` =
    /// force off, omitted = off.
    pub enabled: Option<bool>,
}

/// Placeholder experimental feature.
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TestFeature {
    /// Message to log when the feature is applied.
    pub message: Option<String>,
}

/// Windows Sandbox backend config.
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WindowsSandbox {
    /// Idle timeout before teardown (ms).
    pub idle_timeout_ms: Option<u32>,
    /// Idle timeout (legacy seconds field).
    pub idle_timeout: Option<u32>,
    /// Daemon named-pipe override.
    pub daemon_pipe_name: Option<String>,
}

/// Hyperlight backend config.
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Hyperlight {
    /// Guest runtime that `process.commandLine` is source for; `agent` is
    /// the default.
    pub runtime: Option<crate::mxc_common::models::HyperlightRuntime>,
}

/// MicroVM creation settings retained by contract adapters before normalization.
#[derive(Debug, Clone)]
pub(crate) struct MicroVm {
    pub(crate) image: String,
    pub(crate) memory_mib: Option<u32>,
}

/// WSL container backend config.
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Wslc {
    /// OS inside the WSL container.
    pub target_os: Option<String>,
    /// Container image reference.
    pub image: Option<String>,
    /// Path to a local image tarball.
    pub image_tar_path: Option<String>,
    /// vCPU count.
    pub cpu_count: Option<u32>,
    /// Memory limit (MB).
    pub memory_mb: Option<u64>,
    /// Enable GPU passthrough.
    pub gpu: Option<bool>,
    /// Storage path override.
    pub storage_path: Option<String>,
    /// Host → container port forwards. Only TCP is currently supported; the
    /// parser rejects `udp` because the WSLC SDK runtime returns `E_NOTIMPL`
    /// for UDP port mappings.
    pub port_mappings: Option<Vec<PortMapping>>,
    /// State-aware provision-phase normalization input constructed from the
    /// exact `wslc.provision` contract. Carries the container-creation knobs for
    /// the state-aware lifecycle; the flat sibling fields above remain the
    /// one-shot surface. Absent on one-shot configs and non-provision phases.
    pub provision: Option<WslcProvisionPhase>,
}

/// Unused partial normalization shape for the WSLc **provision** phase: it
/// carries only the image fields and does not track the exact contract, which
/// also declares `portMappings`. State-aware provisioning builds
/// `models::WslcProvisionConfig` directly, so nothing populates this struct.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct WslcProvisionPhase {
    /// Container image reference (e.g. `alpine:latest`). Defaults to
    /// `alpine:latest` when omitted.
    pub image: Option<String>,

    /// Path to a local image tarball to import instead of pulling.
    pub image_tar_path: Option<String>,
}

/// A single host → container port forward retained in normalized WSLC settings.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PortMapping {
    /// Host (Windows) port.
    pub windows_port: u16,
    /// Container port.
    pub container_port: u16,
    /// Transport protocol for the mapping. Only `tcp` is currently supported.
    pub protocol: Option<TransportProtocol>,
}

/// Port-forward transport protocol. Only `tcp` is currently supported by the
/// vendored WSLC SDK runtime; `udp` is rejected at parse time.
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum TransportProtocol {
    Tcp,
}

#[cfg(test)]
mod tests {
    use super::Containment;
    use crate::mxc_common::models::ContainmentBackend;

    const BACKENDS: &[ContainmentBackend] = &[
        ContainmentBackend::ProcessContainer,
        ContainmentBackend::Wslc,
        ContainmentBackend::Lxc,
        ContainmentBackend::Hyperlight,
        ContainmentBackend::WindowsSandbox,
        ContainmentBackend::IsolationSession,
        ContainmentBackend::Seatbelt,
        ContainmentBackend::Bubblewrap,
    ];

    #[test]
    fn runtime_backend_names_are_accepted_by_the_raw_containment_parser() {
        for backend in BACKENDS {
            let parsed = Containment::parse_wire_name(backend.wire_name())
                .unwrap_or_else(|| panic!("unrecognized backend name: {}", backend.wire_name()));
            assert_eq!(
                crate::mxc_common::config_parser::map_wire_containment(Some(&parsed)),
                backend.clone(),
                "{backend:?}"
            );
        }
    }
}