
Go + Lua 脚本执行引擎,提供安全沙箱环境和权限控制,支持 CLI 直接调用和 FFI 共享库调用两种接入方式。
2026-05-11 13:01:46
·
Tool
OShinC/
├── plugin/
│ ├── core.go # 执行引擎 (Lua 脚本执行、内置函数注册)
│ └── sandbox.go # 安全沙箱 (权限模型、脚本验证、环境隔离)
├── cmd/
│ ├── cli/ # 命令行工具 (直接调用 plugin 包)
│ └── ffi/ # FFI 共享库 (cgo 导出 C 接口)
└── test/
├── oshin_core.py # Python 调用封装 (ctypes)
├── example.py # Python 调用示例
└── test_permission.py # 权限系统测试
脚本通过 request_permission() 主动请求权限,宿主程序通过回调决定是否允许。支持预授权白名单、宿主回调、静态 AST 检测三层防护。
| 权限类型 | 说明 | 管控函数 |
|---|---|---|
exec |
执行外部程序 | execute_external() |
network |
网络访问 | http_request() |
file_read |
读取本地文件 | read_file() |
file_write |
写入本地文件 | write_file() |
system |
系统操作 | os.execute(), os.exit(), os.getenv() 等 |
request_permission(type, description)load(), dofile(), loadfile(), loadstring() 等危险函数debug, io, package 等危险全局变量_G["load"] 等方式绕过检测import "oshin-core/plugin"
core := plugin.NewCore()
resp := core.Execute(plugin.PluginRequest{
Script: `function main(params) return {sum = params.a + params.b} end`,
Params: map[string]interface{}{"a": 10, "b": 20},
Mode: "direct",
})
支持直接执行、交互模式、JSON 模式(stdin/stdout,适合脚本编排和 CI/CD)。
通过 cgo 编译为 DLL,导出 C 接口供 Python、Node、Swift 等语言调用。支持权限回调和配置注入。
| 模式 | 说明 |
|---|---|
direct |
直接调用 main(params) |
route |
通过 routes 表按 action 路由 |
pipeline |
执行 pipeline(params) 管道 |
request_permission, http_request, execute_external, read_file, write_file, json_parse, json_stringify, logurl_encode/decode, md5, sha1, sha256, base64_encode/decode, hex_encode/decodeos.time, os.date)无需权限,危险函数(os.execute, os.exit 等)需 system 权限OShinC
© 2026 MoGuQAQ. All rights reserved.