返回 DeepSeek-TUI-2026
windows.rs
根目录 / crates / tui / src / sandbox / windows.rs
1 //! Windows sandbox implementation (best-effort placeholder).
2 //!
3 //! Windows sandboxing can be implemented using:
4 //! - Windows Sandbox (full isolation)
5 //! - AppContainer (process isolation)
6 //! - Restricted tokens (reduced privileges)
7 //!
8 //! This module selects a preferred approach and exposes helpers used by the
9 //! sandbox manager. Full enforcement should be implemented in a helper binary.
10
11 use std::path::Path;
12
13 use super::SandboxPolicy;
14
15 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
16 pub enum WindowsSandboxKind {
17 WindowsSandbox,
18 AppContainer,
19 RestrictedToken,
20 }
21
22 impl std::fmt::Display for WindowsSandboxKind {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 match self {
25 WindowsSandboxKind::WindowsSandbox => write!(f, "sandbox"),
26 WindowsSandboxKind::AppContainer => write!(f, "appcontainer"),
27 WindowsSandboxKind::RestrictedToken => write!(f, "restricted-token"),
28 }
29 }
30 }
31
32 pub fn is_available() -> bool {
33 windows_sandbox_available() || appcontainer_available() || restricted_token_available()
34 }
35
36 pub fn select_best_kind(_policy: &SandboxPolicy, _cwd: &Path) -> WindowsSandboxKind {
37 if windows_sandbox_available() {
38 WindowsSandboxKind::WindowsSandbox
39 } else if appcontainer_available() {
40 WindowsSandboxKind::AppContainer
41 } else {
42 WindowsSandboxKind::RestrictedToken
43 }
44 }
45
46 pub fn detect_denial(exit_code: i32, stderr: &str) -> bool {
47 if exit_code == 0 {
48 return false;
49 }
50
51 let patterns = [
52 "Access is denied",
53 "access denied",
54 "STATUS_ACCESS_DENIED",
55 "privilege",
56 "AppContainer",
57 "sandbox",
58 ];
59
60 patterns.iter().any(|p| stderr.contains(p))
61 }
62
63 fn windows_sandbox_available() -> bool {
64 let Ok(system_root) = std::env::var("SystemRoot") else {
65 return false;
66 };
67 Path::new(&system_root)
68 .join("System32")
69 .join("WindowsSandbox.exe")
70 .exists()
71 }
72
73 fn appcontainer_available() -> bool {
74 true
75 }
76
77 fn restricted_token_available() -> bool {
78 true
79 }
80
80 lines RUST