如何查看 Sandscale Agent 沙盒的 CPU、記憶體、磁碟用量及執行紀錄
Watching what an agent's sandbox is doing: CPU, memory, disk and run history
Sandscale 提供 CLI 指令和 API,讓用戶查看 Agent 沙盒的資源用量、執行命令及單次執行的輸出與成本。`sandscale sandbox metrics ID --follow` 可持續顯示 CPU、記憶體和磁碟用量;`sandscale sandbox logs ID` 可列出執行紀錄。沙盒到達時限後會自動停止,期間仍會計入方案的 vCPU-hours。
Short answer: four CLI commands answer most "what is my agent doing in there?" questions. sandscale sandbox list shows which sandboxes exist, sandscale sandbox metrics ID --follow shows CPU, memory and disk use as it happens, sandscale sandbox logs ID lists the commands that ran, and --run RUN_ID prints one command's output. For code, GET /api/v1/sandbox/runs/{id} returns a run's details and cost.
Everything below is from the live sandscale sandbox reference, sandscale logs reference and sandboxes API guide.
Which sandboxes are running?
sandscale sandbox list
sandscale sandbox show sbx_9
list takes --limit N and --cursor C for paging, and every command here takes --json for scripts. If your agents put labels on the sandboxes they start (--label KEY=VALUE on sandscale sandbox start, or labels in the SDK), you can tie each one back to a task or pull request.
A sandbox your agent forgot to stop still stops when its time limit runs out, but it counts against your plan's vCPU-hours until then. list is the quickest way to spot one.
How hard is it working?
sandscale sandbox metrics sbx_9
sandscale sandbox metrics sbx_9 --follow --interval 10s
metrics prints the sandbox's CPU, memory and disk use. With --follow it prints new samples as they come, one JSON object per line with --json, which is easy to pipe into jq or a log shipper.
What to look for:
- CPU pinned for a long time on a task that should be quick: a loop, or a test suite that hangs waiting for something it cannot reach.
-
Memory climbing toward the box's size: the next command may come back with
oom_killed. Each vCPU comes with 4 GiB; see sizing sandboxes. - Disk filling: an agent writing logs or build output without cleaning up. See resource exhaustion in agent sandboxes.
What did it run?
sandscale sandbox logs sbx_9
sandscale sandbox logs sbx_9 --run run_3
The first lists the sandbox's runs; the second prints one run's output. sandscale logs sandbox ID [--run RUN_ID] is the same view under the top-level logs command, next to workspace and build host logs.
This is useful after the fact: the agent's transcript tells you what it meant to do, and the run history tells you what actually executed.
From code: the run record
Every command run through the API is recorded. The exec answer includes a run_id (runId in the TypeScript SDK), and:
curl "https://api.sandscale.dev/api/v1/sandbox/runs/$RUN_ID" -H "Authorization: Bearer $SANDSCALE_API_KEY"
returns that run's details and cost. Storing the run ID next to the agent step that caused it gives you a per-step cost without estimating. The exec answer itself already has exit_code, duration_ms, and timed_out and oom_killed flags.
Live output while it runs
For your own code rather than a terminal, the TypeScript SDK's run accepts onStdout and onStderr callbacks that receive output in order as the server releases it, and the result's streamed field says whether they got live output or the final output at the end. Streaming sandbox output in TypeScript covers the details.
Who did what
The CLI shows what a sandbox did. Who started it, stopped it and ran which commands is in your organization's hash-chained audit log, which every plan can read in the console and Team and Enterprise can export. Together they cover "what happened" and "who did it". More on how each Sandscale sandbox is isolated is on the product page.
FAQ
How do I see a Sandscale sandbox's CPU and memory use?
Run sandscale sandbox metrics ID. Add --follow to keep printing new samples, --interval to change how often, and --json for one JSON object per line.
How do I see what commands ran in a sandbox?
sandscale sandbox logs ID lists the sandbox's runs, and sandscale sandbox logs ID --run RUN_ID prints one run's output.
Can I get the cost of a single command?
Yes. Every run through the API is recorded, and GET /api/v1/sandbox/runs/{id} with the run ID returns its details and cost.
Do forgotten sandboxes keep running forever?
No. A sandbox stops by itself when its time limit runs out. Until then it counts against your plan's vCPU-hours, so list your sandboxes and stop ones you no longer need.
Related
- Timeouts for agent sandboxes
- Structured logging for agent runs
- Scripting the Sandscale CLI: exit codes and JSON
Originally published on the Sandscale blog.
來源:DEV Community · dev.to