Skip to content

29anan29/leash-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leash

Leash — 面向 AI Agent 的安全脚本语言

能力门控 · 最小特权 · 确定性执行

🌐 简体中文 · English (US) · English (UK) · 繁體中文 · 日本語 · 한국어 · Français · Deutsch · Español · Русский

stars release license ci top-lang last-commit cpp17


对比 Python 写 AI Agent: 没有权限隔离,Agent 拿到什么就能做什么,一不小心就 rm -rf /。

对比 eBPF / WASM 沙箱: 学习成本高,写个 Hello World 要先配工具链。

Leash 的答案: 一门自带沙箱的脚本语言。程序默认零权限——读文件、调模型、访问网络全部需要宿主显式授予的 能力(capability),每一步都有审计日志。语法像 Python,3 分钟上手。


安装

Linux

发行版 安装方式
任意发行版 `curl -fsSL https://github.com/29anan29/leash-cpp/releases/latest/download/install.sh
Ubuntu / Debian 同上(也可手动下载 .tar.gz 解压到 /usr/local/bin
Arch Linux 同上;或从 AUR 安装 leash-bin(规划中 🚧)
Fedora / RHEL 同上

macOS

# Intel 与 Apple Silicon 通用
curl -fsSL https://github.com/29anan29/leash-cpp/releases/latest/download/install-macos.sh | sudo bash

ARM 版本暂用 amd64 构建(Rosetta 2 可运行);IDE 已有原生 arm64 构建。

Windows

# PowerShell(管理员)
iwr -useb https://github.com/29anan29/leash-cpp/releases/latest/download/install.ps1 | iex

或手动安装:

  1. 下载 leash-Windows-amd64.zip
  2. 解压到 C:\leash
  3. C:\leash 加入系统 PATH

从源码构建

git clone https://github.com/29anan29/leash-cpp.git
make
./leash examples/hello.ae

需要 g++ / clang++ 支持 C++17。

预期输出:

Leash 语言 — 安全 Agent 脚本
hello world!
x + y = 50

Release 资产

每次推送 v* tag 时,CI 自动构建并上传以下产物:

内容 格式
leash-{平台}-amd64 leash 编译器 + leash-studio 终端编辑器 .tar.gz / .zip
Leash-{版本}-linux-amd64.deb Linux 图形化安装包(Ubuntu/Debian) .deb
Leash-{版本}-macos-amd64.pkg macOS 图形化安装包 .pkg
Leash-{版本}-windows-amd64-setup.exe Windows 图形化安装向导 .exe (NSIS)
Leash Studio Pro-{版本}-{平台} Electron IDE(Monaco + React) .tar.gz / .zip / portable.exe
install.sh Linux 一键安装脚本
install-macos.sh macOS 一键安装脚本
install.ps1 Windows PowerShell 安装脚本
checksums.txt SHA256 校验和

效果一览

┌─ leash-studio ──────────────────────────────────────────┐
│  1   fn main                                            │
│  2      包 file  os  ai                                 │
│  3      能力注入 ── 编译期门控                          │
│  4      燃料消耗 ── ⛽ @fuel(500)                       │
│  5      超时熔断 ── ⏱ @timeout(3s)                     │
│  6      审计日志 ── 每次 IO/模型调用都记录              │
│  7                                                        │
│  8      let 报告 = read("结果.txt") ── 需要 file 能力   │
│  9      let 答复 = chat("总结一下") ── 需要 ai 能力     │
│ 10      out(答复)                ── 需要 io 能力        │
│ 11                                                        │
│ 12  :q  :w  /search  Ctrl+R 运行                        │
└──────────────────────────────────────────────────────────┘

终端编辑器 leash-studio 是零依赖单文件 C++17,Vim 风格快捷键,语法高亮,CJK 友好。运行 Ctrl+R 即执行当前缓冲区。


为什么不是 Python / WASM / eBPF?

方案 权限隔离 审计 资源限制 学习成本 体积
Leash 编译期能力门控 全量内建 fuel + 超时 + 递归深度 30 分钟 < 2 MB
Python + subprocess 凭运气 靠 ulimit 中等
WASM 沙箱优秀
eBPF 内核级 很高

代码尝鲜

// 文件读后总结 — 安全门控全程守护
package file  ai  os

fn main
  let 数据 = read("sales_2024.csv")        // 需 file 能力
  let 提示  = "用中文总结这份销售数据,突出趋势"
  let 结论  = chat(提示, 数据)               // 需 ai 能力
  write("总结.md", 结论)                     // 需 file 能力
  out("✅ 已生成销售报告:{cwd()}/总结.md")   // 需 io 能力

每条 requires 在编译期检查宿主是否注入相应能力,未授权即拒绝——不像 bash eval("$(curl ...)") 那样裸奔。


✨ 特性

特性 说明
🔒 能力安全模型 默认零权限,package X 声明所需能力,宿主 provideCap 注入
📋 审计日志 每一次 IO / 网络 / AI 调用都有完整审计记录
资源控制 @fuel(N) 步数上限、@timeout(Nms) 超时熔断、递归深度限制
🎯 确定性模式 @deterministic 禁用 now / random / sleep,运行结果可复现
🐍 缩进语法 类 Python,无括号噪音,学习成本极低
📦 开箱即用包 file os ai time random crypto http re json gui
🧩 LangChain 替代 promptx memory llmx chainx toolx agent ragx 等 13 个纯 Leash 包
📚 116+ 标准库 math string list csvx toml yaml httpx
🔧 多文件模块 import "xxx.ae" 递归收集 + 去重 + 环检测
编译到原生 #c 编译模式 / 可选 LLVM 代码生成,接近原生性能
🖥️ 两套编辑器 终端 Vim 风格(零依赖) + Electron IDE(Monaco + React)

生态

编辑器 平台 依赖
leash-studio(终端) Linux / macOS / Windows 零依赖 C++17,Release 附赠
leash-studio-pro(Electron) Linux / macOS / Windows Node.js + npm,Release 附赠安装包

语言支持:VS Code 扩展、Monaco Editor 内建高亮、TextMate 语法包均已就绪。


Star History

Star History Chart

Contributors


项目结构

.github/workflows/   CI 自动构建(打 tag 自动发版)
src/                 编译器核心(C++17)
  frontend/          lexer / parser
  checker/           typecheck
  codegen/           字节码 + LLVM 代码生成
  vm/                虚拟机
  host/              宿主能力注入(file/os/ai 等)
studio/              终端编辑器(单文件 minivim.cpp)
leash-studio-pro/    Electron IDE(Monaco + React)
lib/                 116+ 标准库包
examples/            Hello / 质数报告 / 多文件 / LangChain 框架
light/               TextMate + Monarch 语法高亮
tests/               安全测试(权限门控、编译错误检测)
docs/                多语言 README(9 种语言)
CONTRIBUTING.md      贡献指南
install.sh           Linux 一键安装脚本
install-macos.sh     macOS 一键安装脚本
install.ps1          Windows 一键安装脚本
教程/                完整中文教程

协议

MIT

用 C++17 构建 · GitHub

About

Leash — 给 AI Agent 拴上牵绳:能力门控、最小特权、确定性执行的安全脚本语言

Topics

Resources

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages