# Sandbox Manager

> Manage local app sandbox sessions with separate profiles and window focus control

| | |
|---|---|
| Version | 1.0.1 |
| Category | System |
| Permissions | process.spawn, process.control |
| Depends on | ai-chat |

# Sandbox Manager

## Mục đích

Sandbox Manager là plugin quản lý các session chạy ứng dụng Windows thật. Bản đầu tập trung vào quản lý process và focus cửa sổ, không phải sandbox bảo mật kiểu VM.

## File liên quan

- `plugins-library/sandbox-manager/manifest.json`
- `plugins-library/sandbox-manager/main/index.ts`
- `plugins-library/sandbox-manager/main/sandbox-manager.ts`
- `plugins-library/sandbox-manager/main/window-probe.ts`
- `plugins-library/sandbox-manager/widget.html`
- `plugins-library/sandbox-manager/js/widget.js`
- `plugins-library/sandbox-manager/css/widget.css`
- `plugins-library/sandbox-manager/settings.html`
- `plugins-library/sandbox-manager/js/settings.js`
- `plugins-library/sandbox-manager/css/settings.css`
- `electron/plugin-loader.ts`
- `src/lib/types.ts`

## Cách hoạt động

- Plugin có `mainEntry` riêng và đăng ký IPC channels `plugin:sandbox-manager:*`.
- Mỗi sandbox config lưu trong plugin settings gồm tên, executable path, arguments, working directory, profile directory và trạng thái enabled.
- Runtime giữ session trong `Map<sessionId, Session>`.
- Một session chỉ được có một process root đang chạy. Nếu start lại session đang chạy, plugin trả lỗi thay vì spawn thêm process.
- Khi start, plugin tạo profile directory và spawn app bằng `child_process.spawn`.
- Khi stop, plugin dùng `taskkill /PID <pid> /T /F` để dừng cây process.
- Window list/focus dùng PowerShell gọi Windows APIs: lấy cửa sổ theo process tree và focus HWND bằng `SetForegroundWindow`.

## UI

- Widget hiển thị danh sách sandbox sessions, status, PID, số window, Start/Stop/Restart/Refresh windows/Focus.
- Settings cho phép thêm, sửa, xóa sandbox config và chỉnh auto-refresh interval.

## Giới hạn MVP

- Đây là process/profile isolation, không cô lập bảo mật như Windows Sandbox/VM/container.
- Chưa hỗ trợ click/gõ phím/chuột.
- Chưa hỗ trợ screenshot/capture window.
- Focus có thể thất bại nếu app/game chạy quyền cao hơn, bị anti-cheat chặn, hoặc cửa sổ thật thuộc process launcher phức tạp.
- Nếu app không hỗ trợ profile riêng qua args/env/cwd, mức không xung đột phụ thuộc vào chính app đó.
