初始提交,沉淀 k8s-tenant-wuguirong 租户下完整可信数据空间 的部署、真机/真数据/真多方验证成果。 包含: - CLAUDE.md / docs/:工程入口、armv7 glibc 兼容性整改规格、 ssw-platform#1(armv7 stdout=文件即 exit 100)issue 正文 - build/:TDS 服务端 + tdc-connector 交叉构建脚本、cube 沙箱 编排、三方拓扑/真机验收脚本、ELF 符号扫描工具 - card/:软卡(softcard)源码与预编译产物(local/amd64/armv7) - evidence/:验收报告、三方真实结果、armv7 stdout 矩阵复现证据 - .workbuddy/memory/:工作日志 排除:ssw-tds/ 与 ssw-acz7015/ 为上游源码独立仓库(含 .git, 体积大);build/ 下 ctx-*/dist/pglite-* 等可重建中间产物; build/.env.*、tdc-conn-key/、.tdc-identity-secret 等明文密钥。
102 lines
3.9 KiB
Python
102 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
||
"""cube_exec.py —— CubeSandbox 沙箱执行客户端(用官方 cubesandbox SDK)。
|
||
|
||
用途:把「离线真机」用沙箱模拟出来 —— 在沙箱里跑软卡 + 连接器,
|
||
让它们能对内网 TDS(192.168.1.26:30201)自主心跳。
|
||
|
||
🔴 两个必踩的坑(都踩过):
|
||
1) 本机 HTTP 代理会把**内网明文 HTTP** 改写 ⇒ 必须清 proxy env + NO_PROXY。
|
||
注意 urllib/requests 的 ProxyHandler 在 import 时就建好,事后 pop env 无效,
|
||
要显式 `build_opener(ProxyHandler({}))` 或用 SDK 的自定义 transport。
|
||
2) `xop` 会把 stdout 里的密钥**打码**(sk****)⇒ 不能靠 xop 取 API key,
|
||
要从 ~/.workbuddy/mcp.json 的 header 里读明文。
|
||
|
||
用法:
|
||
python3 build/cube_exec.py <sandbox_id> "shell command"
|
||
python3 build/cube_exec.py --list
|
||
python3 build/cube_exec.py --put <sandbox_id> <local> <remote>
|
||
python3 build/cube_exec.py --get <sandbox_id> <remote> <local>
|
||
"""
|
||
import json
|
||
import os
|
||
import sys
|
||
|
||
for _v in ("HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "http_proxy", "https_proxy", "all_proxy"):
|
||
os.environ.pop(_v, None)
|
||
os.environ["NO_PROXY"] = "192.168.1.30,192.168.1.26,localhost,127.0.0.1"
|
||
os.environ["no_proxy"] = os.environ["NO_PROXY"]
|
||
|
||
from cubesandbox import Config, Sandbox # noqa: E402
|
||
|
||
GATE = os.environ.get("CUBE_GATE", "http://192.168.1.30:3000")
|
||
|
||
|
||
def api_key() -> str:
|
||
env = os.environ.get("CUBE_API_KEY")
|
||
if env:
|
||
return env.strip()
|
||
cfg = json.load(open(os.path.expanduser("~/.workbuddy/mcp.json")))
|
||
key = cfg["mcpServers"]["cube-sandbox"]["headers"]["X-API-Key"]
|
||
return key.strip()
|
||
|
||
|
||
def connect(sandbox_id: str) -> Sandbox:
|
||
# 🔴🔴 必须设 CUBE_PROXY_NODE_IP + CUBE_PROXY_PORT_HTTP(内核手册「连接信息」):
|
||
# 不设 ⇒ SDK 回落**直连**沙箱的 49983(对外关闭)⇒ Connection refused。
|
||
# 设了 ⇒ 走本机 proxy 通道(node:80),并自动带上 e2b-traffic-access-token。
|
||
os.environ.setdefault("CUBE_PROXY_NODE_IP", os.environ.get("CUBE_NODE_IP", "192.168.1.30"))
|
||
os.environ.setdefault("CUBE_PROXY_PORT_HTTP", "80")
|
||
cfg = Config(api_url=GATE, api_key=api_key(), timeout=300, request_timeout=120.0)
|
||
cfg.proxy_node_ip = os.environ["CUBE_PROXY_NODE_IP"]
|
||
cfg.proxy_port = int(os.environ["CUBE_PROXY_PORT_HTTP"])
|
||
return Sandbox.connect(sandbox_id, config=cfg)
|
||
|
||
|
||
def main():
|
||
if len(sys.argv) < 2:
|
||
print(__doc__)
|
||
return
|
||
if sys.argv[1] == "--list":
|
||
cfg = Config(api_url=GATE, api_key=api_key(), timeout=300, request_timeout=60.0)
|
||
print(json.dumps(cfg and _list(cfg), ensure_ascii=False, indent=2))
|
||
return
|
||
if sys.argv[1] == "--put":
|
||
sid, local, remote = sys.argv[2], sys.argv[3], sys.argv[4]
|
||
sb = connect(sid)
|
||
with open(local, "rb") as fh:
|
||
sb.files.write(remote, fh.read())
|
||
print(f"OK put {local} -> {remote}")
|
||
return
|
||
if sys.argv[1] == "--get":
|
||
sid, remote, local = sys.argv[2], sys.argv[3], sys.argv[4]
|
||
sb = connect(sid)
|
||
blob = sb.files.read(remote)
|
||
if isinstance(blob, str):
|
||
blob = blob.encode()
|
||
open(local, "wb").write(blob)
|
||
print(f"OK get {remote} -> {local} ({len(blob)} bytes)")
|
||
return
|
||
sid, cmd = sys.argv[1], sys.argv[2]
|
||
sb = connect(sid)
|
||
r = sb.commands.run(cmd, timeout=1800)
|
||
out = (r.stdout or "")
|
||
err = (r.stderr or "")
|
||
if out:
|
||
print(out, end="" if out.endswith("\n") else "\n")
|
||
if err:
|
||
print("--- stderr ---", file=sys.stderr)
|
||
print(err, file=sys.stderr)
|
||
print(f"[exit={r.exit_code}]")
|
||
|
||
|
||
def _list(cfg):
|
||
import urllib.request
|
||
req = urllib.request.Request(f"{GATE}/sandboxes", headers={"X-API-Key": cfg.api_key})
|
||
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
|
||
with opener.open(req, timeout=60) as resp:
|
||
return json.loads(resp.read().decode())
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|