ling-baseling-base

代码执行

本地/沙箱/容器/Jupyter/E2B 代码执行引擎

在线 Playground

在浏览器中直接体验本页相关 API,无需本地安装 Go 环境。

Code Executor

agentkit/codeexecutor 为 Agent 提供安全代码执行能力,支持多种隔离级别与运行时。

CodeExecutor 接口

type CodeExecutor interface {
    Execute(ctx context.Context, req *ExecuteRequest) (*ExecuteResult, error)
}

LLM Agent 通过 tool/codeexecWithCodeExecutor 接入。

后端一览

隔离级别说明
codeexecutor/local本机进程执行(开发)
codeexecutor/sandboxOS 沙箱(bwrap/seatbelt)
codeexecutor/containerDocker 容器
codeexecutor/jupyterJupyter Kernel
codeexecutor/e2bE2B 云沙箱
codeexecutor/codeactCodeAct Python 网关

本地执行

import (
    "github.com/LingByte/ling-base/agentkit/codeexecutor/local"
    "github.com/LingByte/ling-base/agentkit/agent/llmagent"
)

exec := local.New()
ag, _ := llmagent.New("coder",
    llmagent.WithCodeExecutor(exec),
    llmagent.WithInstruction("You can run Python to solve problems."),
)

沙箱执行

import "github.com/LingByte/ling-base/agentkit/codeexecutor/sandbox"

exec, _ := sandbox.New(
    sandbox.WithAllowedPaths([]string{"/tmp/workspace"}),
    sandbox.WithNetworkPolicy(sandbox.NetworkDeny),
)

工作区

WorkspaceManager / WorkspaceFS 管理 Agent 可访问的文件系统视图,配合 tool/filetool/workspaceexec 使用。

CodeAct 模式

codeexecutor/codeact 实现 CodeAct 范式:LLM 生成 Python → 网关执行 → 结果回传。

import "github.com/LingByte/ling-base/agentkit/codeexecutor/codeact"

gateway, _ := codeact.NewGateway(tools...)

安全建议

  • 生产环境禁止local 执行用户可控代码
  • 使用 sandboxcontainer + 路径白名单
  • 配合 plugin/guardrail 人工审批高危工具调用

On this page