rl-rockcli
v0.0.17
Published
Open-source ROCK CLI - Sandbox and Log management tool
Readme
ROCK CLI (rockcli)
ROCK CLI 是一个开源的命令行工具,用于管理和操作沙箱环境。
功能特性
- 沙箱管理 - 启动、停止、执行、上传/下载文件、交互式 REPL
安装
# 使用 npm 安装
npm install -g rl-rockcli
# 或使用 yarn 安装
yarn global add rl-rockcli使用方法
基本语法
rockcli <command> [options]全局选项
--verbose, -v- 启用详细日志输出--base-url- 服务器地址(覆盖配置文件)
命令详解
基本语法
rockcli sandbox [action] [options]
rockcli sandbox [sandboxId] [action] [options]可用操作
基本操作:
- start - 启动一个新的 sandbox 实例
- stop - 停止指定的 sandbox 实例
- execute - 在 sandbox 中执行命令(别名:exec)
- status - 查看 sandbox 的运行状态
- upload - 上传文件或文件夹到 sandbox
- download - 从 sandbox 下载文件
- write-file - 在 sandbox 中写入文件
- read-file - 从 sandbox 读取文件
- attach - 进入交互式 REPL 模式
Session 管理(子命令):
- session create - 创建 session
- session run - 在 session 中执行命令
- session close - 关闭 session
新语法格式(推荐)
# ID 在前,action 在后(更符合直觉)
rockcli sandbox start
rockcli sandbox <sandbox-id> stop
rockcli sandbox <sandbox-id> status
rockcli sandbox <sandbox-id> attach
# 执行命令(使用 -- 分隔符)
rockcli sandbox <sandbox-id> exec -- ls -la
rockcli sandbox <sandbox-id> exec -- python script.py基本命令示例
# 启动一个新的 sandbox 实例
rockcli sandbox start --image python:3.11 --memory 8g --cpus 2.0
# 停止指定的 sandbox 实例
rockcli sandbox <sandbox-id> stop
# 在 sandbox 中执行命令(支持 -- 分隔符)
rockcli sandbox <sandbox-id> exec -- ls -la
rockcli sandbox <sandbox-id> exec --command "ls -la"
# 查看 sandbox 的运行状态
rockcli sandbox <sandbox-id> status
# 上传单个文件到 sandbox
rockcli sandbox <sandbox-id> upload --file local.txt --target-path /tmp/remote.txt
# 上传文件夹到 sandbox(仅一级文件)
rockcli sandbox <sandbox-id> upload --dir ./src --target-path /app/src
# 递归上传文件夹(保持目录结构)
rockcli sandbox <sandbox-id> upload --dir ./project --target-path /app -r
# 从 sandbox 下载文件
rockcli sandbox <sandbox-id> download --file /tmp/remote.txt
# 在 sandbox 中写入文件
rockcli sandbox <sandbox-id> write-file --content "Hello World" --target-path /tmp/hello.txt
# 从 sandbox 读取文件
rockcli sandbox <sandbox-id> read-file --file /tmp/hello.txt --start-line 1 --end-line 10Session 管理示例
session create - 创建 session
# 创建默认 session
rockcli sandbox <sandbox-id> session create
# 创建自定义名称的 session
rockcli sandbox <sandbox-id> session create --session my-session
# 创建带启动脚本的 session
rockcli sandbox <sandbox-id> session create --startup-source "/root/.bashrc,/app/env.sh"
# 创建带环境变量的 session
rockcli sandbox <sandbox-id> session create --env '{"PATH":"/usr/local/bin:/usr/bin","ENV":"production"}'session run - 在 session 中执行命令
# 使用 -- 分隔符执行命令(推荐)
rockcli sandbox <sandbox-id> session run -- ls -la
rockcli sandbox <sandbox-id> session run -- python script.py --arg1 value1
# 使用 --command 参数
rockcli sandbox <sandbox-id> session run --command "ls -la"
# 在自定义 session 中执行
rockcli sandbox <sandbox-id> session run --session my-session -- ls -la
# 设置超时时间(30秒)
rockcli sandbox <sandbox-id> session run --timeout 30 -- python long_task.pysession close - 关闭 session
# 关闭默认 session
rockcli sandbox <sandbox-id> session close
# 关闭自定义名称的 session
rockcli sandbox <sandbox-id> session close --session my-session交互式 REPL 模式
使用 attach 命令进入交互式模式:
# 进入交互式 REPL
rockcli sandbox <sandbox-id> attachREPL 模式支持:
- 持久 session(export、cd 等命令状态保持)
- 命令历史(上下键浏览)
- Tab 补全
- 内置命令(以
/开头):/upload//download- 文件传输/status- 查看状态/help- 帮助/exit- 退出/close- 关闭 session 并退出
配置文件
默认配置文件路径:~/.rock/settings.json
配置文件格式(JSON):
{
"sandbox": {
"base_url": "http://localhost:8080"
}
}环境变量
支持通过环境变量设置服务器地址:
# 设置服务器地址
export ROCKCLI_BASE_URL=http://localhost:8080
# 或使用 ROCK_BASE_URL(兼容)
export ROCK_BASE_URL=http://localhost:8080
# 使用环境变量运行命令
rockcli sandbox <sandbox-id> status优先级:命令行参数 > 环境变量 > 配置文件
相关资源
- GitHub: https://github.com/your-org/rock-cli
- 文档: https://rock-cli.example.com/docs
- 问题反馈: https://github.com/your-org/rock-cli/issues
许可证
MIT License
Copyright (c) 2026 ROCK CLI Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
