跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

windows_network_process_windows.go

37 行 · 1.1 KB历史下载
1//go:build windows
2
3package workbench
4
5import (
6 "errors"
7 "unsafe"
8
9 "golang.org/x/sys/windows"
10)
11
12// The packet helper keeps this non-inheritable handle until process exit.
13// Windows then retires its relay descendants even if the controller kills
14// the helper before it can run its normal pipe cleanup.
15var windowsNetworkProcessJob windows.Handle
16
17func containWindowsNetworkProcess() error {
18 if windowsNetworkProcessJob != 0 {
19 return nil
20 }
21 job, err := windows.CreateJobObject(nil, nil)
22 if err != nil {
23 return errors.New("Windows 网络进程组无法创建,外网保持关闭")
24 }
25 var limits windows.JOBOBJECT_EXTENDED_LIMIT_INFORMATION
26 limits.BasicLimitInformation.LimitFlags = windows.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
27 _, err = windows.SetInformationJobObject(job, windows.JobObjectExtendedLimitInformation, uintptr(unsafe.Pointer(&limits)), uint32(unsafe.Sizeof(limits)))
28 if err == nil {
29 err = windows.AssignProcessToJobObject(job, windows.CurrentProcess())
30 }
31 if err != nil {
32 _ = windows.CloseHandle(job)
33 return errors.New("Windows 网络子进程无法隔离,外网保持关闭")
34 }
35 windowsNetworkProcessJob = job
36 return nil
37}