mxc-sdk 1.0.1

Importable library for starting MXC sandboxes in-process, with streaming stdio.
Documentation
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

//! AppContainer + BaseContainer backend family, including the
//! T1/T2/T3 isolation-tier fallback ladder and the Windows-only
//! support modules they depend on (job objects, BFS policy,
//! network/proxy plumbing, sandbox tracking, launch diagnostics).
//!
//! All modules are Windows-only. The crate links unconditionally so
//! `wxc-exec` (which always targets Windows) can depend on it
//! without feature gates, while cross-platform consumers of
//! `mxc_common` are unaffected by AppContainer code.

#[cfg(target_os = "windows")]
pub mod appcontainer_runner;
#[cfg(target_os = "windows")]
mod base_container_helpers;
#[cfg(target_os = "windows")]
pub mod base_container_runner;
#[cfg(target_os = "windows")]
pub mod capture_output;
#[cfg(target_os = "windows")]
pub mod dispatcher;
#[cfg(target_os = "windows")]
pub mod fallback_detector;
#[cfg(target_os = "windows")]
pub mod filesystem_bfs;
#[cfg(target_os = "windows")]
pub mod guarded_capture;
#[cfg(target_os = "windows")]
pub mod job_object;
#[cfg(target_os = "windows")]
pub mod launch_diagnostics;
#[cfg(target_os = "windows")]
mod native_capture;
#[cfg(target_os = "windows")]
mod network_policy_helpers;
#[cfg(target_os = "windows")]
pub mod probe;
#[cfg(target_os = "windows")]
pub mod process_mitigation;
#[cfg(target_os = "windows")]
pub mod proxy_coordinator;
#[cfg(target_os = "windows")]
pub mod sandbox_tracking;
#[cfg(target_os = "windows")]
mod secenv;
#[cfg(target_os = "windows")]
pub use native_capture::CaptureSession;
#[cfg(target_os = "windows")]
pub use secenv::{
    is_security_environment_api_available, probe_security_environment_exports,
    ProcessSecurityEnvironment, SecurityEnvironmentApi as ProcessSecurityEnvironmentApi,
    SecurityEnvironmentExportReport, SecurityEnvironmentStartupInfo,
    PROCESS_SECURITY_ENVIRONMENT_FLAG_NONE,
};

#[cfg(target_os = "windows")]
pub(crate) fn validate_process_container_stdio(
    stdio: crate::mxc_common::sandbox_process::StdioMode,
) -> Result<(), crate::mxc_common::models::ScriptResponse> {
    if matches!(stdio, crate::mxc_common::sandbox_process::StdioMode::Pty(_)) {
        return Err(crate::mxc_common::models::ScriptResponse::rejected(
            "ProcessContainer does not support caller-controlled PTY spawning",
        ));
    }
    Ok(())
}

/// Working-directory resolution for both Windows launch paths. Deliberately
/// **not** `cfg`-gated: the mapping is pure, and keeping it portable means its
/// regression tests (notably "never resolve to a `NULL` cwd") run on every CI
/// lane rather than only the Windows one.
pub mod working_directory;

/// Test-only guards that use the crate-wide lock from
/// `crate::mxc_common::test_env`.
#[cfg(all(test, target_os = "windows"))]
pub(crate) mod test_env;

#[cfg(all(test, target_os = "windows"))]
mod tests {
    use crate::mxc_common::sandbox_process::{PtySize, StdioMode};

    #[test]
    fn process_container_rejects_pty_stdio() {
        assert!(
            super::validate_process_container_stdio(StdioMode::Pty(PtySize::default())).is_err()
        );
        assert!(super::validate_process_container_stdio(StdioMode::Pipes).is_ok());
        assert!(super::validate_process_container_stdio(StdioMode::Inherit).is_ok());
    }
}