Skip to content

PoC: Remote Sandbox — Agent ↔ Sandbox via Supabase Realtime #267

@nmhjklnm

Description

@nmhjklnm

目标

用最小原型验证核心假设:agent 通过 Supabase Realtime 远程操控用户电脑上的 sandbox,延迟和体验是否可接受。

背景

当前 agent runtime 和 sandbox 强耦合在同一进程。若要支持云端 sandbox 或用户本机 sandbox,需要通过网络通信。本 PoC 验证 Supabase Realtime broadcast channel 作为通信层的可行性。

架构

┌─────────────────┐  Supabase Realtime  ┌──────────────────┐
│  Server          │    (WebSocket)      │  用户电脑         │
│                  │                     │                  │
│  LangChain Agent │◄═══════════════════►│  Electron App    │
│  - LLM 调用      │  channel:           │  - 执行 shell    │
│  - tool 决策     │  sandbox:{session}  │  - 读写文件       │
│  - 结果推理      │                     │  - 返回结果       │
└─────────────────┘                     └──────────────────┘

通信协议(JSON over Supabase Realtime broadcast)

// agent → sandbox(命令)
{ "type": "fs.read", "id": "req_1", "path": "/workspace/main.py" }
{ "type": "fs.write", "id": "req_2", "path": "/workspace/main.py", "content": "..." }
{ "type": "fs.list", "id": "req_3", "path": "/workspace" }
{ "type": "shell.exec", "id": "req_4", "cmd": "python main.py", "timeout": 30 }

// sandbox → agent(结果)
{ "type": "result", "id": "req_1", "ok": true, "content": "import os\n..." }
{ "type": "result", "id": "req_2", "ok": true }
{ "type": "result", "id": "req_4", "ok": true, "stdout": "Hello\n", "stderr": "", "exit_code": 0 }
{ "type": "result", "id": "req_4", "ok": false, "error": "timeout" }

延迟预估

场景 WebSocket RTT 50 次 fs 操作总开销 占 agent run 比例
同机 localhost ~0.1ms ~5ms <0.01%
云内网 ~1-2ms ~100ms <0.5%
用户本机(公网) ~10-50ms ~2.5s ~5%

可进一步优化:批量 fs 操作、目录树 prefetch、文件缓存。

优势(对比 OpenClaw "agent-inside-sandbox" 模式)

Agent inside sandbox Agent remote + daemon
安全 LLM API key 暴露给 sandbox key 留在中心服务器
sandbox 端重量 需要完整 Python + agent 依赖 极轻量 daemon(几百行)
升级 每个 sandbox 都要更新 agent 中心更新一处
监控 分散 集中

三个组件

组件 技术栈 预估代码量
Agent 端 LangChain + 自定义 Tool(read_file / write_file / shell_exec),Tool 内部 publish 到 Realtime channel 并 await 结果 ~200 行 Python
Electron 端(sandbox-daemon) Supabase JS client 监听 channel,收到命令后 fs.* / child_process.exec,结果 broadcast 回去 ~200 行 TypeScript
通信层 Supabase Realtime broadcast channel(已部署,零额外基础设施) 0

验证指标

  • 延迟:agent 发命令到收到结果的 round-trip time(目标:本机 <50ms)
  • 可靠性:断线重连后命令不丢失
  • 端到端:agent 完成一个完整任务(例:创建 Python 项目 → 写代码 → 运行 → 修 bug → 通过)
  • 体验:Electron 端实时展示执行过程

不在 PoC 范围

  • 生产级错误处理、权限控制
  • sandbox 生命周期管理(mycel-container)
  • 多 sandbox 并发
  • 文件传输优化(大文件、二进制文件)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions