mxc-sdk 1.2.0

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

//! Native ProcessContainer backend using PSEC.
//!
//! 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 Windows backend code.

#[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")]
mod environment;
#[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(crate) mod policy_projection;
#[cfg(target_os = "windows")]
mod policy_restriction;
#[cfg(target_os = "windows")]
pub mod probe;
#[cfg(target_os = "windows")]
pub mod process_mitigation;
#[cfg(target_os = "windows")]
mod secenv;
#[cfg(target_os = "windows")]
mod secenv_policy;
#[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 native ProcessContainer. 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());
        assert!(super::validate_process_container_stdio(StdioMode::MergedPipes).is_ok());
    }
}