TunnelShell
Agent-first remote terminal with persistent PTY sessions
TunnelShell 让 AI Agent 像操作本地终端一样操作远程服务器,支持 PTY 会话持久化、attach/detach/reconnect、文件传输、多会话管理。
为什么需要 TunnelShell?
传统 SSH 工具对 AI Agent 不友好:
- 每次执行命令都是「盲操作」——发命令、等结果、断开
- 无法处理交互式命令(sudo 密码、确认提示、REPL)
- 无法维持上下文(cd 之后路径丢失、环境变量不延续)
- 调试困难,看不到「终端里发生了什么」
TunnelShell 解决这些问题:
- PTY 会话持久化 - attach/detach/reconnect
- 多会话管理 - 命名、共享、恢复
- 终端状态检测 - ready/running/password/confirm/repl
- 文件传输集成 - upload/download/list
- 超时控制与安全机制 - 多级超时、危险命令阻止
安装
pip install tunnel-shell
或从源码安装:
git clone https://github.com/yourusername/tunnel-shell.git
cd tunnel-shell
pip install -e .
快速开始
1. 单命令执行
tunnel-shell exec --host node3 --cmd 'hostname'
2. 会话管理
# 创建会话
tunnel-shell session create --host node3 --name deploy
# 在会话中执行命令
tunnel-shell session attach --name deploy --cmd 'ls -la'
# 列出所有会话
tunnel-shell session list
# 终止会话
tunnel-shell session kill --name deploy
tunnel-shell session kill --all
3. 文件传输
# 上传文件
tunnel-shell file upload --host node3 --local file.txt --remote /tmp/file.txt
# 下载文件
tunnel-shell file download --host node3 --remote /tmp/file.txt --local file.txt
# 列出远程目录
tunnel-shell file list --host node3 --path /home/user
主机配置
TunnelShell 使用 ~/.ssh/config 中的主机配置:
Host node3
HostName 10.16.82.202
Port 22
User wuxiaoran
IdentityFile ~/.ssh/id_rsa
功能特性
PTY 会话持久化
会话在 detach 后保持运行,可以重新连接:
# 创建会话
tunnel-shell session create --host node3 --name mysession
# 执行命令后 detach(会话保持)
tunnel-shell session attach --name mysession --cmd 'top'
# 重新连接
tunnel-shell session attach --name mysession --cmd 'q'
多会话管理
# 创建多个会话
tunnel-shell session create --host node3 --name session1
tunnel-shell session create --host node3 --name session2
# 查看所有会话
tunnel-shell session list
# 批量清理
tunnel-shell session kill --all
命令安全检查
# 分析命令安全性
tunnel-shell analyze "sudo rm -rf /tmp/test"
# 输出:
# Risk Level: medium
# Warnings: Uses sudo, Uses rm -rf
交互提示检测
# 检测文本中的交互提示
tunnel-shell detect "Password:"
# 输出:
# Prompt Type: password
# Message: Password:
会话录制
# 列出录制
tunnel-shell recording list
# 查看录制详情
tunnel-shell recording show session_id
# 导出录制
tunnel-shell recording export session_id -o output.txt
CLI 命令
tunnel-shell --help
Commands:
exec Execute a single command on a remote host
session Session management (create/attach/list/kill)
file File transfer operations (upload/download/list)
analyze Analyze a command for classification and safety
detect Detect interactive prompts in text
recording Session recording operations
使用场景
远程部署
tunnel-shell session create --host node3 --name deploy
tunnel-shell session attach --name deploy --cmd 'cd /app && git pull'
tunnel-shell session attach --name deploy --cmd 'docker-compose up -d'
tunnel-shell session kill --name deploy
日志查看
tunnel-shell exec --host node3 --cmd 'tail -100 /var/log/syslog'
文件同步
tunnel-shell file upload --host node3 --local config.yaml --remote /app/config.yaml
开发
# 克隆仓库
git clone https://github.com/yourusername/tunnel-shell.git
cd tunnel-shell
# 安装开发依赖
pip install -e ".[dev]"
# 运行测试
pytest
# 构建文档
cd docs && make html
许可证
MIT License - 详见 LICENSE
贡献
欢迎提交 Issue 和 Pull Request!
致谢
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tunnel_shell-0.1.0.tar.gz
(26.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tunnel_shell-0.1.0.tar.gz.
File metadata
- Download URL: tunnel_shell-0.1.0.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12d316a29e6f9b74b4879ae7551e4e5cecdef0783abddf9a27011cb6d9c0133d
|
|
| MD5 |
0f69642efb2be4d977c6df003ca013c9
|
|
| BLAKE2b-256 |
101f1a297ba1cbe72c857a6710707df147a89cd45679cf00ad016221f49858d0
|
File details
Details for the file tunnel_shell-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tunnel_shell-0.1.0-py3-none-any.whl
- Upload date:
- Size: 31.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2ea6039356eff7f42a639b33f3fa0e738f9c35f1744d28b6476d420c03c7197
|
|
| MD5 |
ae73987d321cf92ed935696340cc41b4
|
|
| BLAKE2b-256 |
de62a7bc27b77d69b32ac89db366caa037e4569494a281fd09868d2efd80f27c
|