Documentation
¶
Overview ¶
Package container 提供容器隔离执行能力。 允许 AI Agent 在独立容器中执行,通过文件系统 IPC 与主进程通信。
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultBlockedPatterns = []string{
".ssh",
".gnupg",
".gpg",
".aws",
".azure",
".gcloud",
".kube",
".docker",
"credentials",
".env",
".netrc",
".npmrc",
".pypirc",
"id_rsa",
"id_ed25519",
"private_key",
".secret",
}
DefaultBlockedPatterns 默认禁止挂载的路径模式。
Functions ¶
Types ¶
type Config ¶
type Config struct {
Image string // 容器镜像名
MemoryLimit int64 // 内存限制 (bytes)
CPUQuota int64 // CPU 配额
NetworkMode string // 网络模式 (bridge/host/none)
DefaultTimeout time.Duration // 默认超时时间
MaxOutputSize int // 最大输出大小 (bytes)
AllowedEnvVars []string // 允许的环境变量列表
DockerHost string // Docker API 地址(可选)
}
Config 容器执行器配置。
type DockerRunner ¶
type DockerRunner struct {
// contains filtered or unexported fields
}
DockerRunner Docker 容器执行器实现。
func NewDockerRunner ¶
func NewDockerRunner(cfg Config) (*DockerRunner, error)
NewDockerRunner 创建 Docker 执行器。
func (*DockerRunner) Cleanup ¶
func (r *DockerRunner) Cleanup(ctx context.Context) error
Cleanup 清理过期资源。
func (*DockerRunner) Run ¶
func (r *DockerRunner) Run(ctx context.Context, req RunRequest) (*RunResult, error)
Run 在容器中执行 prompt。
type MountValidator ¶
type MountValidator struct {
// contains filtered or unexported fields
}
MountValidator 挂载验证器。
func NewMountValidator ¶
func NewMountValidator(additionalBlocked []string) *MountValidator
NewMountValidator 创建挂载验证器。
func (*MountValidator) Validate ¶
func (v *MountValidator) Validate(hostPath string) ValidateResult
Validate 验证挂载路径。
func (*MountValidator) ValidateMounts ¶
func (v *MountValidator) ValidateMounts(mounts []VolumeMount) (allowed []VolumeMount, rejected []VolumeMount)
ValidateMounts 批量验证挂载路径。 返回验证通过的挂载列表和被拒绝的列表。
type RunRequest ¶
type RunRequest struct {
ChatID string // 会话 ID
SessionID string // Claude CLI session ID
IsNewSession bool // 是否新会话
Prompt string // 执行提示词
WorkspaceDir string // 工作空间目录
SessionsDir string // Claude sessions 目录
IPCDir string // IPC 通信目录
GlobalDir string // 全局记忆目录(只读)
EnvVars map[string]string // 环境变量(已过滤)
Timeout time.Duration // 执行超时
IsMain bool // Main 组有更多权限
Metadata map[string]string // 扩展元数据
}
RunRequest 容器执行请求。
type RunResult ¶
type RunResult struct {
Status string // success / error
Output string // 输出内容
NewSessionID string // 新会话 ID(如有变化)
Duration time.Duration // 执行耗时
ExitCode int // 容器退出码
Error string // 错误信息(如有)
}
RunResult 容器执行结果。
type Runner ¶
type Runner interface {
// Run 在容器中执行 prompt。
// 返回执行结果和错误。
Run(ctx context.Context, req RunRequest) (*RunResult, error)
// Stop 停止指定容器。
Stop(containerID string) error
// Cleanup 清理过期容器资源。
Cleanup(ctx context.Context) error
// Close 关闭执行器,释放资源。
Close() error
}
Runner 容器执行器接口。
type ValidateResult ¶
ValidateResult 验证结果。
type VolumeMount ¶
type VolumeMount struct {
HostPath string // 宿主机路径
ContainerPath string // 容器内路径
ReadOnly bool // 是否只读
}
VolumeMount 卷挂载配置。
Click to show internal directories.
Click to hide internal directories.