跳到正文
浏览文档

指南

文件与命令

执行命令、延续交互式工作,并读取、写入、编辑文件或检查逐行归因。

本页内容+

运行命令

exec_command 把 shell 命令文本作为最后一个位置参数。包含空格或 shell 运算符的命令必须加引号。可选 timeout 限制总执行时间,而 --yield-time-ms 只控制首次等待输出的时间。

Shell
sandbox-runtime-cli --sandbox-id eos-abc exec_command pwd
sandbox-runtime-cli --sandbox-id eos-abc exec_command --yield-time-ms 0 "sleep 30"

未提供工作区会话 ID 时,运行时创建自动会话,并在最后一个命令进入终态后发布更改。只有在集成接口已经提供会话时,才使用已有的 --workspace-session-id

延续交互式工作

仍在运行的响应会包含 command_session_id。可向其 stdin 写入纯文本,或发送程序所需的终端控制字符。CLI 的位置参数 TEXT 会追加到输入流。

Shell
sandbox-runtime-cli --sandbox-id eos-abc write_command_stdin --command-session-id cmd-1 hello
sandbox-runtime-cli --sandbox-id eos-abc write_command_stdin --command-session-id cmd-1 --yield-time-ms 1000 "$'\003'"

第二个示例使用 shell 的 ANSI-C 引号发送 Ctrl-C。当程序需要接收输入结束信号时,仍在运行的命令也接受 Ctrl-D。

读取稳定输出

命令输出使用从零开始的稳定行偏移量。先从偏移量零读取,再从返回或由已消费行数推导出的下一个偏移量继续。默认上限为 200,最大为 1000。

Shell
sandbox-runtime-cli --sandbox-id eos-abc read_command_lines --command-session-id cmd-1 --start-offset 0 --limit 100

读取与写入文件

路径可以是仓库相对路径,也可以是工作区根目录绝对路径。未提供工作区会话 ID 的读取使用最新已发布快照;未提供会话的写入会发布一个归属于 operation:<request_id> 的层。

Shell
sandbox-runtime-cli --sandbox-id eos-abc file_read --path src/main.rs --offset 20 --limit 40
sandbox-runtime-cli --sandbox-id eos-abc --request-id note-1 file_write --path notes.txt --content "hello"

编辑与归因

file_edit 接受按顺序执行的精确字符串替换 JSON 数组。除非 replace_all 为 true,否则每个旧字符串必须唯一。file_blame 随后报告每一条已发布行的不透明所有者。

Shell
sandbox-runtime-cli --sandbox-id eos-abc file_edit --path notes.txt --edits '[{"old_string":"hello","new_string":"hello sandbox"}]'
sandbox-runtime-cli --sandbox-id eos-abc file_blame --path notes.txt

所有者值为 workspace_session:<id>operation:<id>originalunknown。发布语义和导出请继续阅读发布与导出更改

18 个结果