TunnelProxyTunnelProxy — 隧道代理TunnelProxy
v1.0.5为 AI agent 提供的集成。通过用户本地的 TunnelProxy 实现网络代理、远程命令执行及双向文件传输。
详细分析 ▾
运行时依赖
版本
- 将文档中默认 TunnelProxy 示例地址从 "frp.freefrp.net" 更新为通用占位符 "your-frp-server.example.com"。 - 无功能或代码变更;仅为文档示例澄清,避免混淆。 - 版本号从 1.0.4 升至 1.0.5。
安装命令
点击复制本土化适配说明
TunnelProxyTunnelProxy — 隧道代理TunnelProxy 安装说明: 安装命令:npx clawhub@latest install tunnel-proxy
技能文档
🚇 安全警告
本技能可在你的机器上远程执行命令并传输文件。 使用前:- 除非有意暴露服务,否则设置
TUNNEL_HOST=127.0.0.1 - 对外暴露时使用 49152-65535 随机高端口
- 以受限用户身份运行 TunnelProxy
- 执行前检查所含脚本
# TunnelProxy Skill
概述
本技能让云端沙箱中的 AI agent 利用用户本地 TunnelProxy 服务绕过网络限制,提供: 远程命令执行(通过 PTY Shell) 双向文件传输(通过 HTTP 接口) 无限制网络访问(经用户本地连接)快速开始
1. 初始化连接
``python
from tunnel_ops import TunnelOps # 配置用户 TunnelProxy 地址
ops = TunnelOps(
host="your-frp-server.example.com", # 或用户自定义地址
pty_port=27417, # PTY Shell 端口
http_port=8080 # HTTP 文件服务器端口
)
# 验证连通性
if ops.check()["http"] and ops.check()["pty"]:
print("Tunnel 已就绪")
`
2. 执行远程命令
`python
# 在用户机器运行任意命令
output = ops.run_remote("curl -s https://httpbin.org/ip")
print(f"远程 IP: {output}") # 链式命令
ops.run_remote("cd /tmp && ls -la")
`
3. 文件传输
`python
# 从用户设备拉取文件到沙箱
ops.pull_file("/path/on/remote/file.txt", "local_copy.txt") # 将文件从沙箱推送到用户
ops.push_file("./result.tar.gz")
`
4. 获取远程内容
`python
# 经用户网络下载
content = ops.fetch_url("https://arxiv.org/abs/2301.00001") # 带进度下载文件
ops.fetch_url_to_file("https://example.com/large.zip", "./downloaded.zip")
`
5. 安装被墙包
`python
# 经用户网络下载 pip 包
local_tar = ops.pip_download("torch torchvision", target_dir="./packages")
` API 参考
TunnelOps 类
| 方法 | 说明 | 参数 |
|--------|-------------|------------|
| check() | 验证 HTTP 与 PTY 连通性 | 无 |
| run_remote(cmd, timeout) | 执行 shell 命令 | cmd: str, timeout: int = 30 |
| fetch_url(url, timeout) | 经远程 curl GET URL | url: str, timeout: int = 30 |
| fetch_url_to_file(url, path, timeout) | 下载 URL 到本地文件 | url, local_path, timeout |
| pull_file(remote, local) | 下载远程文件 | remote_path, local_path |
| push_file(local) | 上传本地文件到远程 | local_path |
| pip_download(package, target_dir) | 下载 pip 包 | package, target_dir | 环境变量
| 变量 | 默认值 | 说明 |
|----------|---------|-------------|
| TUNNEL_HOST | frp.freefrp.net | TunnelProxy 主机 |
| TUNNEL_PORT | 27417 | PTY Shell 端口 |
| TUNNEL_HTTP_PORT | 8080 | HTTP 文件服务器端口 |
| TUNNEL_TIMEOUT | 30 | 默认命令超时 | 错误处理
`python
try:
output = ops.run_remote("long_running_command", timeout=60)
except socket.timeout:
print("命令超时 - 可增大超时时间")
except ConnectionRefusedError:
print("TunnelProxy 不可达 - 检查服务是否运行")
` 安全提示
本技能授予 agent 对用户机器的完全命令控制权。仅用于:
- 你完全信任且自行控制的 AI agent
- 已了解安全后果的用户
- 具备额外防护措施(防火墙、UPLOAD_MAGIC)的环境
底层用法
无需 Python API 的单命令执行:
`bash
echo 'pwd' | python3 scripts/pty_exec.py
`
或使用 scripts/http_transfer.py 进行文件操作:
`bash
python3 scripts/http_transfer.py ping
python3 scripts/http_transfer.py upload /path/to/file
``