Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultLangs ¶
func DefaultLangs() map[string]LangConfig
func RegisterSandboxTools ¶
func RegisterSandboxTools(registry *tools.ToolRegistry, sb Sandbox) error
RegisterSandboxTools 将沙箱能力注册为 Agent 可调用的工具
Types ¶
type ExecRequest ¶
type ExecRequest struct {
Language string `json:"language"` // python, node, go, shell
Code string `json:"code"` // 代码或命令
Timeout time.Duration `json:"timeout,omitempty"` // 超时,0 用默认值
Env map[string]string `json:"env,omitempty"` // 额外环境变量
Files []InputFile `json:"files,omitempty"` // 执行前创建的文件
}
ExecRequest 执行请求
type ExecResult ¶
type ExecResult struct {
Stdout string `json:"stdout"` // 标准输出
Stderr string `json:"stderr"` // 标准错误
ExitCode int `json:"exit_code"` // 退出码
Duration time.Duration `json:"duration"` // 执行耗时
TimedOut bool `json:"timed_out,omitempty"` // 是否超时
Truncated bool `json:"truncated,omitempty"` // 输出是否被截断
}
ExecResult 执行结果
type InputFile ¶
type InputFile struct {
Path string `json:"path"` // 相对于工作目录的路径
Content string `json:"content"` // 文件内容
}
InputFile 执行前注入的文件
type LangConfig ¶
type LangConfig struct {
Command string `json:"command"` // 可执行命令(如 python3、node)
Args []string `json:"args,omitempty"` // 前置参数(如 ["run"] for go run)
Ext string `json:"ext,omitempty"` // 代码文件扩展名(空 = shell 模式)
InitFiles map[string]string `json:"init_files,omitempty"` // 预创建文件(如 go.mod)
}
LangConfig 语言配置
type ProcessConfig ¶
type ProcessConfig struct {
DefaultTimeout time.Duration // 默认超时(默认 30s)
MaxOutputBytes int // 最大输出字节数(默认 1MB)
AllowedLangs map[string]LangConfig // 语言配置(nil = 使用默认值)
PreloadEnv map[string]string // 新增:每次执行都注入的环境变量
}
ProcessConfig 进程沙箱配置
type ProcessSandbox ¶
type ProcessSandbox struct {
// contains filtered or unexported fields
}
ProcessSandbox 基于子进程的沙箱实现
func NewProcessSandbox ¶
func NewProcessSandbox(config ProcessConfig) *ProcessSandbox
func (*ProcessSandbox) AddLang ¶
func (s *ProcessSandbox) AddLang(name string, config LangConfig)
AddLang 动态添加语言支持
func (*ProcessSandbox) CheckLang ¶
func (s *ProcessSandbox) CheckLang(lang string) error
CheckLang 检查语言是否可用
func (*ProcessSandbox) Execute ¶
func (s *ProcessSandbox) Execute(ctx context.Context, req ExecRequest) (*ExecResult, error)
Click to show internal directories.
Click to hide internal directories.