@stateset/sandbox-cli 1.0.5 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/LICENSE +22 -0
- package/README.md +805 -0
- package/dist/client.d.ts +761 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +684 -12
- package/dist/client.js.map +1 -1
- package/dist/commands/alias.d.ts +5 -0
- package/dist/commands/alias.d.ts.map +1 -0
- package/dist/commands/alias.js +131 -0
- package/dist/commands/alias.js.map +1 -0
- package/dist/commands/api-key.d.ts +3 -0
- package/dist/commands/api-key.d.ts.map +1 -0
- package/dist/commands/api-key.js +119 -0
- package/dist/commands/api-key.js.map +1 -0
- package/dist/commands/artifact.d.ts.map +1 -1
- package/dist/commands/artifact.js +105 -46
- package/dist/commands/artifact.js.map +1 -1
- package/dist/commands/audit.d.ts +3 -0
- package/dist/commands/audit.d.ts.map +1 -0
- package/dist/commands/audit.js +191 -0
- package/dist/commands/audit.js.map +1 -0
- package/dist/commands/auth.d.ts +3 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +126 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/benchmark.d.ts +3 -0
- package/dist/commands/benchmark.d.ts.map +1 -0
- package/dist/commands/benchmark.js +166 -0
- package/dist/commands/benchmark.js.map +1 -0
- package/dist/commands/billing.d.ts +3 -0
- package/dist/commands/billing.d.ts.map +1 -0
- package/dist/commands/billing.js +139 -0
- package/dist/commands/billing.js.map +1 -0
- package/dist/commands/checkpoint.d.ts.map +1 -1
- package/dist/commands/checkpoint.js +105 -48
- package/dist/commands/checkpoint.js.map +1 -1
- package/dist/commands/completion.d.ts +3 -0
- package/dist/commands/completion.d.ts.map +1 -0
- package/dist/commands/completion.js +134 -0
- package/dist/commands/completion.js.map +1 -0
- package/dist/commands/computer-use.d.ts +3 -0
- package/dist/commands/computer-use.d.ts.map +1 -0
- package/dist/commands/computer-use.js +124 -0
- package/dist/commands/computer-use.js.map +1 -0
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +2 -1
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/context.d.ts +3 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +98 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/cp.d.ts +3 -0
- package/dist/commands/cp.d.ts.map +1 -0
- package/dist/commands/cp.js +165 -0
- package/dist/commands/cp.js.map +1 -0
- package/dist/commands/deploy.d.ts +3 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +68 -20
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/diff.d.ts +3 -0
- package/dist/commands/diff.d.ts.map +1 -0
- package/dist/commands/diff.js +186 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/doctor.d.ts +30 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +177 -207
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/egress.d.ts +3 -0
- package/dist/commands/egress.d.ts.map +1 -0
- package/dist/commands/egress.js +155 -0
- package/dist/commands/egress.js.map +1 -0
- package/dist/commands/env.d.ts +3 -0
- package/dist/commands/env.d.ts.map +1 -0
- package/dist/commands/env.js +169 -0
- package/dist/commands/env.js.map +1 -0
- package/dist/commands/governance.d.ts +47 -0
- package/dist/commands/governance.d.ts.map +1 -0
- package/dist/commands/governance.js +345 -0
- package/dist/commands/governance.js.map +1 -0
- package/dist/commands/grade.d.ts +41 -0
- package/dist/commands/grade.d.ts.map +1 -1
- package/dist/commands/grade.js +255 -160
- package/dist/commands/grade.js.map +1 -1
- package/dist/commands/history.d.ts +4 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +157 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/images.d.ts +8 -0
- package/dist/commands/images.d.ts.map +1 -0
- package/dist/commands/images.js +145 -0
- package/dist/commands/images.js.map +1 -0
- package/dist/commands/info.d.ts +3 -0
- package/dist/commands/info.d.ts.map +1 -0
- package/dist/commands/info.js +86 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +185 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/logs.d.ts +3 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +129 -0
- package/dist/commands/logs.js.map +1 -0
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +141 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/open.d.ts +3 -0
- package/dist/commands/open.d.ts.map +1 -0
- package/dist/commands/open.js +96 -0
- package/dist/commands/open.js.map +1 -0
- package/dist/commands/platform-status.d.ts +25 -5
- package/dist/commands/platform-status.d.ts.map +1 -1
- package/dist/commands/platform-status.js +199 -149
- package/dist/commands/platform-status.js.map +1 -1
- package/dist/commands/plugin.d.ts +5 -0
- package/dist/commands/plugin.d.ts.map +1 -0
- package/dist/commands/plugin.js +126 -0
- package/dist/commands/plugin.js.map +1 -0
- package/dist/commands/pool.d.ts.map +1 -1
- package/dist/commands/pool.js +52 -66
- package/dist/commands/pool.js.map +1 -1
- package/dist/commands/profile.d.ts +3 -0
- package/dist/commands/profile.d.ts.map +1 -0
- package/dist/commands/profile.js +107 -0
- package/dist/commands/profile.js.map +1 -0
- package/dist/commands/repl.d.ts +3 -0
- package/dist/commands/repl.d.ts.map +1 -0
- package/dist/commands/repl.js +390 -0
- package/dist/commands/repl.js.map +1 -0
- package/dist/commands/run.d.ts +3 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +121 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/sandbox-processes.d.ts +27 -0
- package/dist/commands/sandbox-processes.d.ts.map +1 -0
- package/dist/commands/sandbox-processes.js +195 -0
- package/dist/commands/sandbox-processes.js.map +1 -0
- package/dist/commands/sandbox.d.ts.map +1 -1
- package/dist/commands/sandbox.js +506 -98
- package/dist/commands/sandbox.js.map +1 -1
- package/dist/commands/secret.d.ts +3 -0
- package/dist/commands/secret.d.ts.map +1 -0
- package/dist/commands/secret.js +128 -0
- package/dist/commands/secret.js.map +1 -0
- package/dist/commands/session.d.ts.map +1 -1
- package/dist/commands/session.js +285 -52
- package/dist/commands/session.js.map +1 -1
- package/dist/commands/snapshot.d.ts +3 -0
- package/dist/commands/snapshot.d.ts.map +1 -0
- package/dist/commands/snapshot.js +253 -0
- package/dist/commands/snapshot.js.map +1 -0
- package/dist/commands/ssh.d.ts +5 -0
- package/dist/commands/ssh.d.ts.map +1 -0
- package/dist/commands/ssh.js +154 -0
- package/dist/commands/ssh.js.map +1 -0
- package/dist/commands/template.d.ts +3 -0
- package/dist/commands/template.d.ts.map +1 -0
- package/dist/commands/template.js +102 -0
- package/dist/commands/template.js.map +1 -0
- package/dist/commands/terminal.d.ts +53 -0
- package/dist/commands/terminal.d.ts.map +1 -0
- package/dist/commands/terminal.js +381 -0
- package/dist/commands/terminal.js.map +1 -0
- package/dist/commands/top.d.ts +3 -0
- package/dist/commands/top.d.ts.map +1 -0
- package/dist/commands/top.js +116 -0
- package/dist/commands/top.js.map +1 -0
- package/dist/commands/tunnel.d.ts.map +1 -1
- package/dist/commands/tunnel.js +73 -26
- package/dist/commands/tunnel.js.map +1 -1
- package/dist/commands/update.d.ts +3 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +51 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/wait.d.ts +3 -0
- package/dist/commands/wait.d.ts.map +1 -0
- package/dist/commands/wait.js +64 -0
- package/dist/commands/wait.js.map +1 -0
- package/dist/commands/webhook.d.ts +3 -0
- package/dist/commands/webhook.d.ts.map +1 -0
- package/dist/commands/webhook.js +169 -0
- package/dist/commands/webhook.js.map +1 -0
- package/dist/config.d.ts +14 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +109 -16
- package/dist/config.js.map +1 -1
- package/dist/index.js +165 -11
- package/dist/index.js.map +1 -1
- package/dist/sandboxctl.d.ts +3 -0
- package/dist/sandboxctl.d.ts.map +1 -0
- package/dist/sandboxctl.js +37 -0
- package/dist/sandboxctl.js.map +1 -0
- package/dist/utils/context.d.ts +23 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +48 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/credentials.d.ts +8 -0
- package/dist/utils/credentials.d.ts.map +1 -0
- package/dist/utils/credentials.js +120 -0
- package/dist/utils/credentials.js.map +1 -0
- package/dist/utils/dry-run.d.ts +4 -0
- package/dist/utils/dry-run.d.ts.map +1 -0
- package/dist/utils/dry-run.js +24 -0
- package/dist/utils/dry-run.js.map +1 -0
- package/dist/utils/egress-policy.d.ts +31 -0
- package/dist/utils/egress-policy.d.ts.map +1 -0
- package/dist/utils/egress-policy.js +83 -0
- package/dist/utils/egress-policy.js.map +1 -0
- package/dist/utils/errors.d.ts +53 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +278 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/file-content.d.ts +10 -0
- package/dist/utils/file-content.d.ts.map +1 -0
- package/dist/utils/file-content.js +14 -0
- package/dist/utils/file-content.js.map +1 -0
- package/dist/utils/grade-target.d.ts +12 -0
- package/dist/utils/grade-target.d.ts.map +1 -0
- package/dist/utils/grade-target.js +106 -0
- package/dist/utils/grade-target.js.map +1 -0
- package/dist/utils/health-report.d.ts +18 -0
- package/dist/utils/health-report.d.ts.map +1 -0
- package/dist/utils/health-report.js +43 -0
- package/dist/utils/health-report.js.map +1 -0
- package/dist/utils/output.d.ts +20 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/output.js +123 -0
- package/dist/utils/output.js.map +1 -0
- package/dist/utils/plugins.d.ts +17 -0
- package/dist/utils/plugins.d.ts.map +1 -0
- package/dist/utils/plugins.js +57 -0
- package/dist/utils/plugins.js.map +1 -0
- package/dist/utils/resource-class.d.ts +12 -0
- package/dist/utils/resource-class.d.ts.map +1 -0
- package/dist/utils/resource-class.js +17 -0
- package/dist/utils/resource-class.js.map +1 -0
- package/dist/utils/shutdown.d.ts +14 -0
- package/dist/utils/shutdown.d.ts.map +1 -0
- package/dist/utils/shutdown.js +54 -0
- package/dist/utils/shutdown.js.map +1 -0
- package/dist/utils/tty.d.ts +44 -0
- package/dist/utils/tty.d.ts.map +1 -0
- package/dist/utils/tty.js +93 -0
- package/dist/utils/tty.js.map +1 -0
- package/dist/utils/warnings.d.ts +4 -0
- package/dist/utils/warnings.d.ts.map +1 -0
- package/dist/utils/warnings.js +22 -0
- package/dist/utils/warnings.js.map +1 -0
- package/dist/utils/watch.d.ts +7 -0
- package/dist/utils/watch.d.ts.map +1 -0
- package/dist/utils/watch.js +55 -0
- package/dist/utils/watch.js.map +1 -0
- package/dist/workbench/actions.d.ts +26 -0
- package/dist/workbench/actions.d.ts.map +1 -0
- package/dist/workbench/actions.js +38 -0
- package/dist/workbench/actions.js.map +1 -0
- package/dist/workbench/agent-chat.d.ts +71 -0
- package/dist/workbench/agent-chat.d.ts.map +1 -0
- package/dist/workbench/agent-chat.js +223 -0
- package/dist/workbench/agent-chat.js.map +1 -0
- package/dist/workbench/batch-uploads.d.ts +36 -0
- package/dist/workbench/batch-uploads.d.ts.map +1 -0
- package/dist/workbench/batch-uploads.js +154 -0
- package/dist/workbench/batch-uploads.js.map +1 -0
- package/dist/workbench/commands.d.ts +6 -0
- package/dist/workbench/commands.d.ts.map +1 -0
- package/dist/workbench/commands.js +511 -0
- package/dist/workbench/commands.js.map +1 -0
- package/dist/workbench/connection-failure.d.ts +9 -0
- package/dist/workbench/connection-failure.d.ts.map +1 -0
- package/dist/workbench/connection-failure.js +27 -0
- package/dist/workbench/connection-failure.js.map +1 -0
- package/dist/workbench/connection.d.ts +4 -0
- package/dist/workbench/connection.d.ts.map +1 -0
- package/dist/workbench/connection.js +28 -0
- package/dist/workbench/connection.js.map +1 -0
- package/dist/workbench/creation.d.ts +22 -0
- package/dist/workbench/creation.d.ts.map +1 -0
- package/dist/workbench/creation.js +102 -0
- package/dist/workbench/creation.js.map +1 -0
- package/dist/workbench/credits.d.ts +11 -0
- package/dist/workbench/credits.d.ts.map +1 -0
- package/dist/workbench/credits.js +132 -0
- package/dist/workbench/credits.js.map +1 -0
- package/dist/workbench/docker.d.ts +18 -0
- package/dist/workbench/docker.d.ts.map +1 -0
- package/dist/workbench/docker.js +207 -0
- package/dist/workbench/docker.js.map +1 -0
- package/dist/workbench/execution.d.ts +14 -0
- package/dist/workbench/execution.d.ts.map +1 -0
- package/dist/workbench/execution.js +24 -0
- package/dist/workbench/execution.js.map +1 -0
- package/dist/workbench/files.d.ts +51 -0
- package/dist/workbench/files.d.ts.map +1 -0
- package/dist/workbench/files.js +80 -0
- package/dist/workbench/files.js.map +1 -0
- package/dist/workbench/history.d.ts +34 -0
- package/dist/workbench/history.d.ts.map +1 -0
- package/dist/workbench/history.js +50 -0
- package/dist/workbench/history.js.map +1 -0
- package/dist/workbench/input-batch-commands.d.ts +6 -0
- package/dist/workbench/input-batch-commands.d.ts.map +1 -0
- package/dist/workbench/input-batch-commands.js +41 -0
- package/dist/workbench/input-batch-commands.js.map +1 -0
- package/dist/workbench/kitty-diacritics.d.ts +2 -0
- package/dist/workbench/kitty-diacritics.d.ts.map +1 -0
- package/dist/workbench/kitty-diacritics.js +22 -0
- package/dist/workbench/kitty-diacritics.js.map +1 -0
- package/dist/workbench/kitty-graphics.d.ts +59 -0
- package/dist/workbench/kitty-graphics.d.ts.map +1 -0
- package/dist/workbench/kitty-graphics.js +263 -0
- package/dist/workbench/kitty-graphics.js.map +1 -0
- package/dist/workbench/live-execution.d.ts +51 -0
- package/dist/workbench/live-execution.d.ts.map +1 -0
- package/dist/workbench/live-execution.js +222 -0
- package/dist/workbench/live-execution.js.map +1 -0
- package/dist/workbench/model.d.ts +106 -0
- package/dist/workbench/model.d.ts.map +1 -0
- package/dist/workbench/model.js +236 -0
- package/dist/workbench/model.js.map +1 -0
- package/dist/workbench/overview.d.ts +11 -0
- package/dist/workbench/overview.d.ts.map +1 -0
- package/dist/workbench/overview.js +92 -0
- package/dist/workbench/overview.js.map +1 -0
- package/dist/workbench/png.d.ts +10 -0
- package/dist/workbench/png.d.ts.map +1 -0
- package/dist/workbench/png.js +51 -0
- package/dist/workbench/png.js.map +1 -0
- package/dist/workbench/python-task.d.ts +21 -0
- package/dist/workbench/python-task.d.ts.map +1 -0
- package/dist/workbench/python-task.js +52 -0
- package/dist/workbench/python-task.js.map +1 -0
- package/dist/workbench/registry-commands.d.ts +8 -0
- package/dist/workbench/registry-commands.d.ts.map +1 -0
- package/dist/workbench/registry-commands.js +93 -0
- package/dist/workbench/registry-commands.js.map +1 -0
- package/dist/workbench/registry.d.ts +76 -0
- package/dist/workbench/registry.d.ts.map +1 -0
- package/dist/workbench/registry.js +353 -0
- package/dist/workbench/registry.js.map +1 -0
- package/dist/workbench/renderer.d.ts +6 -0
- package/dist/workbench/renderer.d.ts.map +1 -0
- package/dist/workbench/renderer.js +18 -0
- package/dist/workbench/renderer.js.map +1 -0
- package/dist/workbench/results.d.ts +15 -0
- package/dist/workbench/results.d.ts.map +1 -0
- package/dist/workbench/results.js +29 -0
- package/dist/workbench/results.js.map +1 -0
- package/dist/workbench/task-archive.d.ts +23 -0
- package/dist/workbench/task-archive.d.ts.map +1 -0
- package/dist/workbench/task-archive.js +56 -0
- package/dist/workbench/task-archive.js.map +1 -0
- package/dist/workbench/task-board.d.ts +26 -0
- package/dist/workbench/task-board.d.ts.map +1 -0
- package/dist/workbench/task-board.js +43 -0
- package/dist/workbench/task-board.js.map +1 -0
- package/dist/workbench/task-monitor.d.ts +35 -0
- package/dist/workbench/task-monitor.d.ts.map +1 -0
- package/dist/workbench/task-monitor.js +176 -0
- package/dist/workbench/task-monitor.js.map +1 -0
- package/dist/workbench/tasks.d.ts +93 -0
- package/dist/workbench/tasks.d.ts.map +1 -0
- package/dist/workbench/tasks.js +195 -0
- package/dist/workbench/tasks.js.map +1 -0
- package/dist/workbench/terminal.d.ts +82 -0
- package/dist/workbench/terminal.d.ts.map +1 -0
- package/dist/workbench/terminal.js +2577 -0
- package/dist/workbench/terminal.js.map +1 -0
- package/dist/workbench/text.d.ts +10 -0
- package/dist/workbench/text.d.ts.map +1 -0
- package/dist/workbench/text.js +72 -0
- package/dist/workbench/text.js.map +1 -0
- package/dist/workbench/uploads.d.ts +12 -0
- package/dist/workbench/uploads.d.ts.map +1 -0
- package/dist/workbench/uploads.js +16 -0
- package/dist/workbench/uploads.js.map +1 -0
- package/dist/workbench/worker-launch.d.ts +10 -0
- package/dist/workbench/worker-launch.d.ts.map +1 -0
- package/dist/workbench/worker-launch.js +30 -0
- package/dist/workbench/worker-launch.js.map +1 -0
- package/dist/workbench/worker-monitor.d.ts +33 -0
- package/dist/workbench/worker-monitor.d.ts.map +1 -0
- package/dist/workbench/worker-monitor.js +142 -0
- package/dist/workbench/worker-monitor.js.map +1 -0
- package/dist/workbench/worker-output.d.ts +8 -0
- package/dist/workbench/worker-output.d.ts.map +1 -0
- package/dist/workbench/worker-output.js +32 -0
- package/dist/workbench/worker-output.js.map +1 -0
- package/dist/workbench/worker-result.d.ts +29 -0
- package/dist/workbench/worker-result.d.ts.map +1 -0
- package/dist/workbench/worker-result.js +85 -0
- package/dist/workbench/worker-result.js.map +1 -0
- package/dist/workbench/workers.d.ts +49 -0
- package/dist/workbench/workers.d.ts.map +1 -0
- package/dist/workbench/workers.js +53 -0
- package/dist/workbench/workers.js.map +1 -0
- package/package.json +38 -17
- package/dist/__tests__/client.test.d.ts +0 -2
- package/dist/__tests__/client.test.d.ts.map +0 -1
- package/dist/__tests__/client.test.js +0 -198
- package/dist/__tests__/client.test.js.map +0 -1
- package/dist/__tests__/config.test.d.ts +0 -2
- package/dist/__tests__/config.test.d.ts.map +0 -1
- package/dist/__tests__/config.test.js +0 -74
- package/dist/__tests__/config.test.js.map +0 -1
- package/dist/__tests__/utils-cli.test.d.ts +0 -2
- package/dist/__tests__/utils-cli.test.d.ts.map +0 -1
- package/dist/__tests__/utils-cli.test.js +0 -35
- package/dist/__tests__/utils-cli.test.js.map +0 -1
package/dist/commands/sandbox.js
CHANGED
|
@@ -4,7 +4,46 @@ import ora from 'ora';
|
|
|
4
4
|
import { table } from 'table';
|
|
5
5
|
import { getClient } from '../client.js';
|
|
6
6
|
import { getConfig } from '../config.js';
|
|
7
|
-
import {
|
|
7
|
+
import { parseIntOption, formatDateTime, } from '../utils/cli.js';
|
|
8
|
+
import { withRetry, handleCommandError } from '../utils/errors.js';
|
|
9
|
+
import { resolveFormat, formatOutput } from '../utils/output.js';
|
|
10
|
+
import { dryRunGuard } from '../utils/dry-run.js';
|
|
11
|
+
import { printCheckpointWarnings } from '../utils/warnings.js';
|
|
12
|
+
import { watchLoop } from '../utils/watch.js';
|
|
13
|
+
import { registerProcessCommands } from './sandbox-processes.js';
|
|
14
|
+
import { governanceCreateFields, registerSandboxEgressCommand, registerTimelineCommand } from './governance.js';
|
|
15
|
+
import { resourceClassCreateField } from '../utils/resource-class.js';
|
|
16
|
+
import { confirmedCommandExitCode } from '../workbench/execution.js';
|
|
17
|
+
import { fileReadBytes } from '../utils/file-content.js';
|
|
18
|
+
const sandboxRecovery = 'Inspect with `stateset sandbox get <sandbox-id>` before repeating.';
|
|
19
|
+
const branchRecovery = 'Inspect `stateset sandbox list` and the source sandbox before repeating; a new sandbox may already exist.';
|
|
20
|
+
const workspaceRecovery = 'Inspect workspace files with `stateset sandbox list-files <sandbox-id>` before repeating.';
|
|
21
|
+
function toSandboxView(value) {
|
|
22
|
+
const sandbox = value;
|
|
23
|
+
return {
|
|
24
|
+
id: sandbox.id ?? sandbox.sandbox_id ?? '',
|
|
25
|
+
sessionId: sandbox.sessionId ?? sandbox.session_id ?? '',
|
|
26
|
+
status: sandbox.status ?? 'unknown',
|
|
27
|
+
createdAt: sandbox.createdAt ?? sandbox.created_at ?? '',
|
|
28
|
+
expiresAt: sandbox.expiresAt ?? sandbox.expires_at ?? '',
|
|
29
|
+
podIp: sandbox.podIp ?? sandbox.pod_ip,
|
|
30
|
+
maxExpiresAt: sandbox.maxExpiresAt ?? sandbox.max_expires_at,
|
|
31
|
+
maxLifetimeSeconds: sandbox.maxLifetimeSeconds ?? sandbox.max_lifetime_seconds,
|
|
32
|
+
remainingExtendSeconds: sandbox.remainingExtendSeconds ?? sandbox.remaining_extend_seconds,
|
|
33
|
+
lifetimeUsedSeconds: sandbox.lifetimeUsedSeconds ?? sandbox.lifetime_used_seconds,
|
|
34
|
+
lifetimeUsedPercent: sandbox.lifetimeUsedPercent ?? sandbox.lifetime_used_percent,
|
|
35
|
+
requestedAdditionalSeconds: sandbox.requestedAdditionalSeconds ?? sandbox.requested_additional_seconds,
|
|
36
|
+
appliedAdditionalSeconds: sandbox.appliedAdditionalSeconds ?? sandbox.applied_additional_seconds,
|
|
37
|
+
additionalSeconds: sandbox.additionalSeconds ?? sandbox.additional_seconds,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const SANDBOX_COLUMNS = [
|
|
41
|
+
{ key: 'id', header: 'ID', transform: (v) => String(v ?? '').substring(0, 20) },
|
|
42
|
+
{ key: 'status', header: 'Status' },
|
|
43
|
+
{ key: 'createdAt', header: 'Created', transform: (v) => formatDateTime(v) },
|
|
44
|
+
{ key: 'expiresAt', header: 'Expires', transform: (v) => formatDateTime(v) },
|
|
45
|
+
{ key: 'sessionId', header: 'Session', transform: (v) => String(v ?? '').substring(0, 12) },
|
|
46
|
+
];
|
|
8
47
|
export const sandboxCommand = new Command('sandbox')
|
|
9
48
|
.description('Manage sandbox environments');
|
|
10
49
|
// Create sandbox
|
|
@@ -12,15 +51,48 @@ sandboxCommand
|
|
|
12
51
|
.command('create')
|
|
13
52
|
.description('Create a new sandbox')
|
|
14
53
|
.option('-t, --timeout <seconds>', 'Sandbox timeout in seconds')
|
|
54
|
+
.option('--startup-timeout <seconds>', 'Client wait for sandbox creation (1-600 seconds)', '210')
|
|
15
55
|
.option('-c, --cpus <cpus>', 'CPU limit (e.g., "0.5", "1")')
|
|
16
56
|
.option('-m, --memory <memory>', 'Memory limit (e.g., "512Mi", "1Gi")')
|
|
17
|
-
.option('-i, --isolation <isolation>', 'Isolation level (container, gvisor, microvm)')
|
|
57
|
+
.option('-i, --isolation <isolation>', 'Isolation level (container, gvisor, microvm, kata)')
|
|
58
|
+
.option('--desktop-os <os>', 'Desktop OS (linux, windows, macos)', 'linux')
|
|
59
|
+
.option('--resource-class <class>', 'Resource class: shared (burstable, preemptible Spot capacity, 4 vCPU / 8 GB = $0.028/h) or dedicated (guaranteed). Default: the deployment default')
|
|
60
|
+
.option('--durable', 'Create a durable sandbox that is recovered after pod/node loss')
|
|
18
61
|
.option('-e, --env <env...>', 'Environment variables (KEY=VALUE)')
|
|
62
|
+
.option('--egress-allow <rules...>', 'Only allow egress to these hosts / *.domains / IPs / CIDRs (narrows the org policy)')
|
|
63
|
+
.option('--egress-deny <rules...>', 'Deny egress to these hosts / *.domains / IPs / CIDRs')
|
|
64
|
+
.option('--credential <spec...>', 'Egress gateway credential: host=<host>,secret=<SECRET_NAME>[,header=..][,format=..][,path_prefix=..] (secret scope egress)')
|
|
65
|
+
.option('--max-cost-cents <cents>', 'Run budget: stop at this cost (compute + LLM)')
|
|
66
|
+
.option('--max-llm-tokens <n>', 'Run budget: LLM gateway tokens (input + output)')
|
|
67
|
+
.option('--max-runtime <seconds>', 'Run budget: billable runtime')
|
|
68
|
+
.option('--on-exhausted <action>', 'When the budget is spent: stop (default), pause, notify')
|
|
19
69
|
.action(async (options) => {
|
|
70
|
+
const config = getConfig();
|
|
71
|
+
const timeoutSeconds = parseIntOption(options.timeout, { label: 'timeout', min: 1, defaultValue: config.defaultTimeout });
|
|
72
|
+
const startupTimeoutMs = parseIntOption(options.startupTimeout, {
|
|
73
|
+
label: 'startup-timeout', min: 1, max: 600,
|
|
74
|
+
}) * 1000;
|
|
75
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
76
|
+
let resourceClass;
|
|
77
|
+
try {
|
|
78
|
+
resourceClass = resourceClassCreateField(options.resourceClass);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
handleCommandError(error);
|
|
82
|
+
}
|
|
83
|
+
if (dryRunGuard(globalOpts, 'sandbox create', {
|
|
84
|
+
Timeout: `${timeoutSeconds}s`,
|
|
85
|
+
'Startup wait': `${startupTimeoutMs / 1000}s`,
|
|
86
|
+
CPUs: options.cpus,
|
|
87
|
+
Memory: options.memory,
|
|
88
|
+
Isolation: options.isolation,
|
|
89
|
+
'Resource class': resourceClass.resource_class,
|
|
90
|
+
'Desktop OS': options.desktopOs,
|
|
91
|
+
Durable: options.durable ? 'yes' : undefined,
|
|
92
|
+
}))
|
|
93
|
+
return;
|
|
20
94
|
const spinner = ora('Creating sandbox...').start();
|
|
21
95
|
try {
|
|
22
|
-
const config = getConfig();
|
|
23
|
-
const timeoutSeconds = parseIntOption(options.timeout, { label: 'timeout', min: 1, defaultValue: config.defaultTimeout });
|
|
24
96
|
const client = getClient();
|
|
25
97
|
const env = {};
|
|
26
98
|
if (options.env) {
|
|
@@ -30,25 +102,29 @@ sandboxCommand
|
|
|
30
102
|
}
|
|
31
103
|
}
|
|
32
104
|
const result = await client.sandbox.create({
|
|
105
|
+
startupTimeoutMs,
|
|
33
106
|
timeout_seconds: timeoutSeconds,
|
|
34
107
|
cpus: options.cpus,
|
|
35
108
|
memory: options.memory,
|
|
36
109
|
isolation: options.isolation,
|
|
110
|
+
desktop_os: options.desktopOs !== 'linux' ? options.desktopOs : undefined,
|
|
111
|
+
durable: options.durable ? true : undefined,
|
|
37
112
|
env: Object.keys(env).length > 0 ? env : undefined,
|
|
113
|
+
...resourceClass,
|
|
114
|
+
...governanceCreateFields(options),
|
|
38
115
|
});
|
|
116
|
+
const sandbox = toSandboxView(result);
|
|
39
117
|
spinner.succeed('Sandbox created');
|
|
40
118
|
console.log();
|
|
41
|
-
console.log(chalk.green('Sandbox ID:'),
|
|
42
|
-
console.log(chalk.gray('Session ID:'),
|
|
43
|
-
console.log(chalk.gray('Expires at:'),
|
|
119
|
+
console.log(chalk.green('Sandbox ID:'), sandbox.id);
|
|
120
|
+
console.log(chalk.gray('Session ID:'), sandbox.sessionId);
|
|
121
|
+
console.log(chalk.gray('Expires at:'), sandbox.expiresAt);
|
|
44
122
|
console.log();
|
|
45
123
|
console.log(chalk.gray('Run commands with:'));
|
|
46
|
-
console.log(chalk.cyan(` stateset sandbox exec ${
|
|
124
|
+
console.log(chalk.cyan(` stateset sandbox exec ${sandbox.id} -- <command>`));
|
|
47
125
|
}
|
|
48
126
|
catch (error) {
|
|
49
|
-
|
|
50
|
-
console.error(chalk.red(formatCliError(error)));
|
|
51
|
-
process.exit(1);
|
|
127
|
+
handleCommandError(error, spinner);
|
|
52
128
|
}
|
|
53
129
|
});
|
|
54
130
|
// List sandboxes
|
|
@@ -57,14 +133,17 @@ sandboxCommand
|
|
|
57
133
|
.alias('ls')
|
|
58
134
|
.description('List all sandboxes')
|
|
59
135
|
.option('--json', 'Output as JSON')
|
|
136
|
+
.option('-w, --watch', 'Watch for changes')
|
|
137
|
+
.option('-i, --interval <seconds>', 'Watch interval in seconds', '5')
|
|
60
138
|
.action(async (options) => {
|
|
61
|
-
const
|
|
62
|
-
|
|
139
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
140
|
+
const format = resolveFormat({ ...options, ...globalOpts });
|
|
141
|
+
const renderList = async () => {
|
|
63
142
|
const client = getClient();
|
|
64
|
-
const result = await client.sandbox.list();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
console.log(
|
|
143
|
+
const result = await withRetry(() => client.sandbox.list());
|
|
144
|
+
if (format !== 'table') {
|
|
145
|
+
const views = result.sandboxes.map(toSandboxView);
|
|
146
|
+
console.log(formatOutput(views, { format, columns: SANDBOX_COLUMNS, emptyMessage: 'No sandboxes found' }));
|
|
68
147
|
return;
|
|
69
148
|
}
|
|
70
149
|
if (result.sandboxes.length === 0) {
|
|
@@ -73,21 +152,32 @@ sandboxCommand
|
|
|
73
152
|
}
|
|
74
153
|
const tableData = [
|
|
75
154
|
['ID', 'Status', 'Created', 'Expires', 'Extend Left', 'Session'].map(h => chalk.bold(h)),
|
|
76
|
-
...result.sandboxes.map((
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
155
|
+
...result.sandboxes.map((value) => {
|
|
156
|
+
const sandbox = toSandboxView(value);
|
|
157
|
+
return [
|
|
158
|
+
sandbox.id.substring(0, 20),
|
|
159
|
+
colorStatus(sandbox.status),
|
|
160
|
+
formatDate(sandbox.createdAt),
|
|
161
|
+
formatDate(sandbox.expiresAt),
|
|
162
|
+
formatRemainingExtendBudget(sandbox.remainingExtendSeconds),
|
|
163
|
+
sandbox.sessionId.substring(0, 12),
|
|
164
|
+
];
|
|
165
|
+
}),
|
|
84
166
|
];
|
|
85
167
|
console.log(table(tableData));
|
|
168
|
+
};
|
|
169
|
+
if (options.watch) {
|
|
170
|
+
const intervalMs = parseIntOption(options.interval, { label: 'interval', min: 1 }) * 1000;
|
|
171
|
+
await watchLoop(renderList, { intervalMs });
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const spinner = ora('Fetching sandboxes...').start();
|
|
175
|
+
try {
|
|
176
|
+
spinner.stop();
|
|
177
|
+
await renderList();
|
|
86
178
|
}
|
|
87
179
|
catch (error) {
|
|
88
|
-
|
|
89
|
-
console.error(chalk.red(formatCliError(error)));
|
|
90
|
-
process.exit(1);
|
|
180
|
+
handleCommandError(error, spinner);
|
|
91
181
|
}
|
|
92
182
|
});
|
|
93
183
|
// Get sandbox details
|
|
@@ -99,43 +189,41 @@ sandboxCommand
|
|
|
99
189
|
const spinner = ora('Fetching sandbox...').start();
|
|
100
190
|
try {
|
|
101
191
|
const client = getClient();
|
|
102
|
-
const result = await client.sandbox.get(sandboxId);
|
|
192
|
+
const result = await withRetry(() => client.sandbox.get(sandboxId), { spinner });
|
|
193
|
+
const sandbox = toSandboxView(result);
|
|
103
194
|
spinner.stop();
|
|
104
|
-
|
|
105
|
-
|
|
195
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
196
|
+
const format = resolveFormat({ ...options, ...globalOpts });
|
|
197
|
+
if (format !== 'table') {
|
|
198
|
+
const { formatSingleOutput } = await import('../utils/output.js');
|
|
199
|
+
console.log(formatSingleOutput(sandbox, { format }));
|
|
106
200
|
return;
|
|
107
201
|
}
|
|
108
202
|
console.log(chalk.bold('Sandbox Details'));
|
|
109
|
-
console.log(chalk.gray('
|
|
110
|
-
console.log(`ID: ${
|
|
111
|
-
console.log(`Session: ${
|
|
112
|
-
console.log(`Status: ${colorStatus(
|
|
113
|
-
if (
|
|
114
|
-
console.log(`Pod IP: ${
|
|
115
|
-
}
|
|
116
|
-
console.log(`Created: ${formatDateTime(result.created_at)}`);
|
|
117
|
-
console.log(`Expires: ${formatDateTime(result.expires_at)}`);
|
|
118
|
-
if (result.max_expires_at) {
|
|
119
|
-
console.log(`Max Expires: ${formatDateTime(result.max_expires_at)}`);
|
|
203
|
+
console.log(chalk.gray('\u2500'.repeat(40)));
|
|
204
|
+
console.log(`ID: ${sandbox.id}`);
|
|
205
|
+
console.log(`Session: ${sandbox.sessionId}`);
|
|
206
|
+
console.log(`Status: ${colorStatus(sandbox.status)}`);
|
|
207
|
+
if (sandbox.podIp) {
|
|
208
|
+
console.log(`Pod IP: ${sandbox.podIp}`);
|
|
120
209
|
}
|
|
121
|
-
|
|
122
|
-
|
|
210
|
+
console.log(`Created: ${formatDateTime(sandbox.createdAt)}`);
|
|
211
|
+
console.log(`Expires: ${formatDateTime(sandbox.expiresAt)}`);
|
|
212
|
+
if (sandbox.maxExpiresAt) {
|
|
213
|
+
console.log(`Max Expires: ${formatDateTime(sandbox.maxExpiresAt)}`);
|
|
123
214
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
? (lifetimeMetadata.lifetime_used_seconds / lifetimeMetadata.max_lifetime_seconds) * 100
|
|
215
|
+
if (typeof sandbox.lifetimeUsedSeconds === 'number'
|
|
216
|
+
&& typeof sandbox.maxLifetimeSeconds === 'number') {
|
|
217
|
+
const usedPercent = typeof sandbox.lifetimeUsedPercent === 'number'
|
|
218
|
+
? sandbox.lifetimeUsedPercent
|
|
219
|
+
: (sandbox.maxLifetimeSeconds > 0
|
|
220
|
+
? (sandbox.lifetimeUsedSeconds / sandbox.maxLifetimeSeconds) * 100
|
|
131
221
|
: 0);
|
|
132
|
-
console.log(`Lifetime: ${formatBudgetDuration(
|
|
222
|
+
console.log(`Lifetime: ${formatBudgetDuration(sandbox.lifetimeUsedSeconds)} / ${formatBudgetDuration(sandbox.maxLifetimeSeconds)} (${usedPercent.toFixed(2)}%)`);
|
|
133
223
|
}
|
|
134
224
|
}
|
|
135
225
|
catch (error) {
|
|
136
|
-
|
|
137
|
-
console.error(chalk.red(formatCliError(error)));
|
|
138
|
-
process.exit(1);
|
|
226
|
+
handleCommandError(error, spinner);
|
|
139
227
|
}
|
|
140
228
|
});
|
|
141
229
|
// Execute command in sandbox
|
|
@@ -148,10 +236,17 @@ sandboxCommand
|
|
|
148
236
|
const spinner = ora('Executing command...').start();
|
|
149
237
|
try {
|
|
150
238
|
const client = getClient();
|
|
239
|
+
// The SDK retries only provably unsent calls. An outer generic retry
|
|
240
|
+
// would replay a command after a lost response or ambiguous server error.
|
|
151
241
|
const result = await client.sandbox.execute(sandboxId, command);
|
|
152
242
|
spinner.stop();
|
|
153
|
-
|
|
154
|
-
|
|
243
|
+
const exitCode = confirmedCommandExitCode(result);
|
|
244
|
+
process.exitCode = exitCode ?? 1;
|
|
245
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
246
|
+
const format = resolveFormat({ ...options, ...globalOpts });
|
|
247
|
+
if (format !== 'table') {
|
|
248
|
+
const { formatSingleOutput } = await import('../utils/output.js');
|
|
249
|
+
console.log(formatSingleOutput(result, { format }));
|
|
155
250
|
return;
|
|
156
251
|
}
|
|
157
252
|
if (result.stdout) {
|
|
@@ -160,15 +255,15 @@ sandboxCommand
|
|
|
160
255
|
if (result.stderr) {
|
|
161
256
|
console.error(chalk.yellow(result.stderr));
|
|
162
257
|
}
|
|
163
|
-
if (
|
|
164
|
-
console.
|
|
165
|
-
|
|
258
|
+
if (exitCode === undefined) {
|
|
259
|
+
console.error(chalk.yellow('Outcome unknown. Inspect the execution before repeating; do not automatically retry.'));
|
|
260
|
+
}
|
|
261
|
+
else if (exitCode !== 0) {
|
|
262
|
+
console.log(chalk.red(`Exit code: ${exitCode}`));
|
|
166
263
|
}
|
|
167
264
|
}
|
|
168
265
|
catch (error) {
|
|
169
|
-
|
|
170
|
-
console.error(chalk.red(formatCliError(error)));
|
|
171
|
-
process.exit(1);
|
|
266
|
+
handleCommandError(error, spinner);
|
|
172
267
|
}
|
|
173
268
|
});
|
|
174
269
|
// Stop sandbox
|
|
@@ -176,16 +271,166 @@ sandboxCommand
|
|
|
176
271
|
.command('stop <sandbox-id>')
|
|
177
272
|
.description('Stop a sandbox')
|
|
178
273
|
.action(async (sandboxId) => {
|
|
274
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
275
|
+
if (dryRunGuard(globalOpts, 'sandbox stop', { 'Sandbox ID': sandboxId }))
|
|
276
|
+
return;
|
|
179
277
|
const spinner = ora('Stopping sandbox...').start();
|
|
180
278
|
try {
|
|
181
279
|
const client = getClient();
|
|
182
|
-
|
|
183
|
-
|
|
280
|
+
// Let the SDK decide which transport attempts are safe. An outer retry
|
|
281
|
+
// can repeat a mutation after its response was lost.
|
|
282
|
+
const result = await client.sandbox.stop(sandboxId);
|
|
283
|
+
if (result?.success !== true)
|
|
284
|
+
throw new Error('Sandbox stop was not acknowledged.');
|
|
285
|
+
spinner.succeed(`Stop acknowledged for sandbox ${sandboxId}`);
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
handleCommandError(error, spinner, { mutationRecovery: sandboxRecovery });
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
// Fork sandbox
|
|
292
|
+
sandboxCommand
|
|
293
|
+
.command('fork <sandbox-id>')
|
|
294
|
+
.description('Fork a sandbox into a new one from a checkpoint of its state')
|
|
295
|
+
.option('--no-env', 'Do not carry environment variables into the fork')
|
|
296
|
+
.option('--name <name>', 'Checkpoint name')
|
|
297
|
+
.action(async (sandboxId, options) => {
|
|
298
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
299
|
+
if (dryRunGuard(globalOpts, 'sandbox fork', { 'Sandbox ID': sandboxId }))
|
|
300
|
+
return;
|
|
301
|
+
const spinner = ora('Forking sandbox...').start();
|
|
302
|
+
try {
|
|
303
|
+
const client = getClient();
|
|
304
|
+
const result = await client.sandbox.fork(sandboxId, {
|
|
305
|
+
include_env: options.env !== false,
|
|
306
|
+
checkpoint_name: options.name,
|
|
307
|
+
});
|
|
308
|
+
spinner.succeed(`Sandbox forked: ${result.forked_id}`);
|
|
309
|
+
console.log(chalk.gray('Checkpoint:'), result.checkpoint_id);
|
|
310
|
+
printCheckpointWarnings(result.warnings);
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
handleCommandError(error, spinner, { mutationRecovery: branchRecovery });
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
// Promote sandbox to another isolation tier
|
|
317
|
+
sandboxCommand
|
|
318
|
+
.command('promote <sandbox-id>')
|
|
319
|
+
.description('Promote a sandbox into a different isolation tier')
|
|
320
|
+
.requiredOption('--isolation <tier>', 'Target isolation (container, gvisor, microvm, kata, wasm)')
|
|
321
|
+
.option('--no-env', 'Do not carry environment variables into the promoted sandbox')
|
|
322
|
+
.option('--stop-source', 'Stop the source sandbox after promotion')
|
|
323
|
+
.action(async (sandboxId, options) => {
|
|
324
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
325
|
+
if (dryRunGuard(globalOpts, 'sandbox promote', { 'Sandbox ID': sandboxId, 'Isolation': options.isolation }))
|
|
326
|
+
return;
|
|
327
|
+
const spinner = ora('Promoting sandbox...').start();
|
|
328
|
+
try {
|
|
329
|
+
const client = getClient();
|
|
330
|
+
const result = await client.sandbox.promote(sandboxId, {
|
|
331
|
+
target_isolation: options.isolation,
|
|
332
|
+
include_env: options.env !== false,
|
|
333
|
+
stop_source: options.stopSource,
|
|
334
|
+
});
|
|
335
|
+
spinner.succeed(`Sandbox promoted: ${result.promoted_id}`);
|
|
336
|
+
console.log(chalk.gray('Checkpoint:'), result.checkpoint_id);
|
|
337
|
+
printCheckpointWarnings(result.warnings);
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
handleCommandError(error, spinner, { mutationRecovery: branchRecovery });
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
// Pause a sandbox (snapshot mode: durable sandboxes; filesystem kept, memory and processes not)
|
|
344
|
+
sandboxCommand
|
|
345
|
+
.command('pause <sandbox-id>')
|
|
346
|
+
.description('Pause a durable sandbox: its pod is stopped, its workspace kept; billing stops until resumed')
|
|
347
|
+
.option('--no-wait', 'Return as soon as the pause has started (202 pausing)')
|
|
348
|
+
.option('--timeout <seconds>', 'Longest wait for the pause to finish (max 120)')
|
|
349
|
+
.option('--json', 'Output as JSON')
|
|
350
|
+
.action(async (sandboxId, options) => {
|
|
351
|
+
const timeoutSeconds = options.timeout !== undefined
|
|
352
|
+
? parseIntOption(options.timeout, { label: 'timeout', min: 1, max: 120 })
|
|
353
|
+
: undefined;
|
|
354
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
355
|
+
if (dryRunGuard(globalOpts, 'sandbox pause', {
|
|
356
|
+
'Sandbox ID': sandboxId,
|
|
357
|
+
'Wait': options.wait !== false ? 'yes' : 'no',
|
|
358
|
+
}))
|
|
359
|
+
return;
|
|
360
|
+
const spinner = ora('Pausing sandbox...').start();
|
|
361
|
+
try {
|
|
362
|
+
const client = getClient();
|
|
363
|
+
const result = await client.sandbox.pause(sandboxId, { wait: options.wait !== false, timeoutSeconds });
|
|
364
|
+
if (result?.sandbox_id !== sandboxId || !['paused', 'pausing'].includes(result.status)) {
|
|
365
|
+
throw new Error('Sandbox pause was not confirmed for the requested sandbox.');
|
|
366
|
+
}
|
|
367
|
+
spinner.stop();
|
|
368
|
+
const format = resolveFormat({ ...options, ...globalOpts });
|
|
369
|
+
if (format !== 'table') {
|
|
370
|
+
const { formatSingleOutput } = await import('../utils/output.js');
|
|
371
|
+
console.log(formatSingleOutput(result, { format }));
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if (result.status === 'pausing') {
|
|
375
|
+
console.log(chalk.yellow(`Sandbox ${sandboxId} is pausing`));
|
|
376
|
+
console.log(chalk.gray('Check with:'), `stateset sandbox get ${sandboxId}`);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
console.log(chalk.green(`Sandbox ${sandboxId} paused`));
|
|
380
|
+
if (result.paused_at)
|
|
381
|
+
console.log(chalk.gray('Paused at:'), result.paused_at);
|
|
382
|
+
if (typeof result.remaining_timeout_seconds === 'number') {
|
|
383
|
+
console.log(chalk.gray('Lifetime left on resume:'), formatDuration(result.remaining_timeout_seconds));
|
|
384
|
+
}
|
|
385
|
+
if (result.paused_expires_at)
|
|
386
|
+
console.log(chalk.gray('Stopped if still paused at:'), result.paused_expires_at);
|
|
387
|
+
console.log(chalk.gray('Kept: workspace filesystem. Not kept: memory, running processes.'));
|
|
184
388
|
}
|
|
185
389
|
catch (error) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
390
|
+
handleCommandError(error, spinner, { mutationRecovery: sandboxRecovery });
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
// Resume a paused sandbox
|
|
394
|
+
sandboxCommand
|
|
395
|
+
.command('resume <sandbox-id>')
|
|
396
|
+
.description('Resume a paused sandbox (a fresh pod on the same workspace)')
|
|
397
|
+
.option('--no-wait', 'Return as soon as the resume has started (202 resuming)')
|
|
398
|
+
.option('--timeout <seconds>', 'Longest wait for the sandbox to be running (max 120)')
|
|
399
|
+
.option('--json', 'Output as JSON')
|
|
400
|
+
.action(async (sandboxId, options) => {
|
|
401
|
+
const timeoutSeconds = options.timeout !== undefined
|
|
402
|
+
? parseIntOption(options.timeout, { label: 'timeout', min: 1, max: 120 })
|
|
403
|
+
: undefined;
|
|
404
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
405
|
+
if (dryRunGuard(globalOpts, 'sandbox resume', {
|
|
406
|
+
'Sandbox ID': sandboxId,
|
|
407
|
+
'Wait': options.wait !== false ? 'yes' : 'no',
|
|
408
|
+
}))
|
|
409
|
+
return;
|
|
410
|
+
const spinner = ora('Resuming sandbox...').start();
|
|
411
|
+
try {
|
|
412
|
+
const client = getClient();
|
|
413
|
+
const result = await client.sandbox.resume(sandboxId, { wait: options.wait !== false, timeoutSeconds });
|
|
414
|
+
if (result?.sandbox_id !== sandboxId || !['running', 'resuming'].includes(result.status)) {
|
|
415
|
+
throw new Error('Sandbox resume was not confirmed for the requested sandbox.');
|
|
416
|
+
}
|
|
417
|
+
spinner.stop();
|
|
418
|
+
const format = resolveFormat({ ...options, ...globalOpts });
|
|
419
|
+
if (format !== 'table') {
|
|
420
|
+
const { formatSingleOutput } = await import('../utils/output.js');
|
|
421
|
+
console.log(formatSingleOutput(result, { format }));
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (result.status === 'resuming') {
|
|
425
|
+
console.log(chalk.yellow(`Sandbox ${sandboxId} is resuming`));
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
console.log(chalk.green(`Sandbox ${sandboxId} is running`));
|
|
429
|
+
if (result.expires_at)
|
|
430
|
+
console.log(chalk.gray('Expires at:'), result.expires_at);
|
|
431
|
+
}
|
|
432
|
+
catch (error) {
|
|
433
|
+
handleCommandError(error, spinner, { mutationRecovery: sandboxRecovery });
|
|
189
434
|
}
|
|
190
435
|
});
|
|
191
436
|
// Extend sandbox lifetime
|
|
@@ -195,24 +440,32 @@ sandboxCommand
|
|
|
195
440
|
.option('-s, --seconds <seconds>', 'Additional lifetime in seconds', '900')
|
|
196
441
|
.option('--json', 'Output as JSON')
|
|
197
442
|
.action(async (sandboxId, options) => {
|
|
443
|
+
const seconds = parseIntOption(options.seconds, { label: 'seconds', min: 60 });
|
|
444
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
445
|
+
if (dryRunGuard(globalOpts, 'sandbox extend', {
|
|
446
|
+
'Sandbox ID': sandboxId,
|
|
447
|
+
'Additional seconds': seconds,
|
|
448
|
+
}))
|
|
449
|
+
return;
|
|
198
450
|
const spinner = ora('Extending sandbox lifetime...').start();
|
|
199
451
|
try {
|
|
200
|
-
const seconds = parseIntOption(options.seconds, { label: 'seconds', min: 60 });
|
|
201
452
|
const client = getClient();
|
|
202
453
|
const result = await client.sandbox.extend(sandboxId, seconds);
|
|
454
|
+
const sandbox = toSandboxView(result);
|
|
203
455
|
spinner.stop();
|
|
204
|
-
|
|
205
|
-
|
|
456
|
+
const format = resolveFormat({ ...options, ...globalOpts });
|
|
457
|
+
if (format !== 'table') {
|
|
458
|
+
const { formatSingleOutput } = await import('../utils/output.js');
|
|
459
|
+
console.log(formatSingleOutput(result, { format }));
|
|
206
460
|
return;
|
|
207
461
|
}
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
? extensionMetadata.requested_additional_seconds
|
|
462
|
+
const requestedSeconds = typeof sandbox.requestedAdditionalSeconds === 'number'
|
|
463
|
+
? sandbox.requestedAdditionalSeconds
|
|
211
464
|
: seconds;
|
|
212
|
-
const appliedSeconds = typeof
|
|
213
|
-
?
|
|
214
|
-
: (typeof
|
|
215
|
-
?
|
|
465
|
+
const appliedSeconds = typeof sandbox.appliedAdditionalSeconds === 'number'
|
|
466
|
+
? sandbox.appliedAdditionalSeconds
|
|
467
|
+
: (typeof sandbox.additionalSeconds === 'number'
|
|
468
|
+
? sandbox.additionalSeconds
|
|
216
469
|
: requestedSeconds);
|
|
217
470
|
if (appliedSeconds < requestedSeconds) {
|
|
218
471
|
console.log(chalk.yellow(`Sandbox ${sandboxId} extension capped at ${formatDuration(appliedSeconds)} (requested ${formatDuration(requestedSeconds)})`));
|
|
@@ -220,17 +473,15 @@ sandboxCommand
|
|
|
220
473
|
else {
|
|
221
474
|
console.log(chalk.green(`Sandbox ${sandboxId} extended by ${formatDuration(appliedSeconds)}`));
|
|
222
475
|
}
|
|
223
|
-
console.log(chalk.gray('Status:'),
|
|
224
|
-
console.log(chalk.gray('Expires at:'),
|
|
225
|
-
const remainingExtendSeconds =
|
|
476
|
+
console.log(chalk.gray('Status:'), sandbox.status);
|
|
477
|
+
console.log(chalk.gray('Expires at:'), sandbox.expiresAt);
|
|
478
|
+
const remainingExtendSeconds = sandbox.remainingExtendSeconds;
|
|
226
479
|
if (typeof remainingExtendSeconds === 'number') {
|
|
227
480
|
console.log(chalk.gray('Remaining extend budget:'), formatRemainingExtendBudget(remainingExtendSeconds));
|
|
228
481
|
}
|
|
229
482
|
}
|
|
230
483
|
catch (error) {
|
|
231
|
-
|
|
232
|
-
console.error(chalk.red(formatCliError(error)));
|
|
233
|
-
process.exit(1);
|
|
484
|
+
handleCommandError(error, spinner, { mutationRecovery: sandboxRecovery });
|
|
234
485
|
}
|
|
235
486
|
});
|
|
236
487
|
// Write file to sandbox
|
|
@@ -238,6 +489,13 @@ sandboxCommand
|
|
|
238
489
|
.command('write <sandbox-id> <path> <content>')
|
|
239
490
|
.description('Write a file to a sandbox')
|
|
240
491
|
.action(async (sandboxId, path, content) => {
|
|
492
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
493
|
+
if (dryRunGuard(globalOpts, 'sandbox write', {
|
|
494
|
+
'Sandbox ID': sandboxId,
|
|
495
|
+
Path: path,
|
|
496
|
+
'Content length': `${content.length} chars`,
|
|
497
|
+
}))
|
|
498
|
+
return;
|
|
241
499
|
const spinner = ora('Writing file...').start();
|
|
242
500
|
try {
|
|
243
501
|
const client = getClient();
|
|
@@ -245,9 +503,7 @@ sandboxCommand
|
|
|
245
503
|
spinner.succeed(`File written to ${path}`);
|
|
246
504
|
}
|
|
247
505
|
catch (error) {
|
|
248
|
-
|
|
249
|
-
console.error(chalk.red(formatCliError(error)));
|
|
250
|
-
process.exit(1);
|
|
506
|
+
handleCommandError(error, spinner, { mutationRecovery: workspaceRecovery });
|
|
251
507
|
}
|
|
252
508
|
});
|
|
253
509
|
// Read file from sandbox
|
|
@@ -258,14 +514,12 @@ sandboxCommand
|
|
|
258
514
|
const spinner = ora('Reading file...').start();
|
|
259
515
|
try {
|
|
260
516
|
const client = getClient();
|
|
261
|
-
const content = await client.sandbox.readFile(sandboxId, path);
|
|
517
|
+
const content = await withRetry(() => client.sandbox.readFile(sandboxId, path), { spinner });
|
|
262
518
|
spinner.stop();
|
|
263
|
-
console.log(
|
|
519
|
+
console.log(fileReadBytes(content).toString('utf8'));
|
|
264
520
|
}
|
|
265
521
|
catch (error) {
|
|
266
|
-
|
|
267
|
-
console.error(chalk.red(formatCliError(error)));
|
|
268
|
-
process.exit(1);
|
|
522
|
+
handleCommandError(error, spinner);
|
|
269
523
|
}
|
|
270
524
|
});
|
|
271
525
|
// List files in sandbox
|
|
@@ -280,10 +534,18 @@ sandboxCommand
|
|
|
280
534
|
const spinner = ora('Listing files...').start();
|
|
281
535
|
try {
|
|
282
536
|
const client = getClient();
|
|
283
|
-
const result = await client.sandbox.listFiles(sandboxId, options.path, { recursive: options.recursive });
|
|
537
|
+
const result = await withRetry(() => client.sandbox.listFiles(sandboxId, options.path, { recursive: options.recursive }), { spinner });
|
|
284
538
|
spinner.stop();
|
|
285
|
-
|
|
286
|
-
|
|
539
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
540
|
+
const format = resolveFormat({ ...options, ...globalOpts });
|
|
541
|
+
if (format !== 'table') {
|
|
542
|
+
const fileColumns = [
|
|
543
|
+
{ key: 'name', header: 'Name' },
|
|
544
|
+
{ key: 'type', header: 'Type' },
|
|
545
|
+
{ key: 'size', header: 'Size', transform: (v) => formatFileSize(v) },
|
|
546
|
+
{ key: 'modified_at', header: 'Modified', transform: (v) => formatDateTime(v) },
|
|
547
|
+
];
|
|
548
|
+
console.log(formatOutput(result.files, { format, columns: fileColumns, emptyMessage: 'No files found' }));
|
|
287
549
|
return;
|
|
288
550
|
}
|
|
289
551
|
if (result.files.length === 0) {
|
|
@@ -302,9 +564,146 @@ sandboxCommand
|
|
|
302
564
|
console.log(table(tableData));
|
|
303
565
|
}
|
|
304
566
|
catch (error) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
567
|
+
handleCommandError(error, spinner);
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
// Glob files
|
|
571
|
+
sandboxCommand
|
|
572
|
+
.command('glob <sandbox-id> <pattern>')
|
|
573
|
+
.description('Find files matching a glob pattern')
|
|
574
|
+
.option('--json', 'Output as JSON')
|
|
575
|
+
.action(async (sandboxId, pattern, options) => {
|
|
576
|
+
const spinner = ora('Searching files...').start();
|
|
577
|
+
try {
|
|
578
|
+
const client = getClient();
|
|
579
|
+
const result = await withRetry(() => client.sandbox.glob(sandboxId, pattern), { spinner });
|
|
580
|
+
const files = Array.isArray(result) ? result : result.files || [];
|
|
581
|
+
spinner.stop();
|
|
582
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
583
|
+
const format = resolveFormat({ ...options, ...globalOpts });
|
|
584
|
+
if (format !== 'table') {
|
|
585
|
+
console.log(formatOutput(files.map((f) => ({ path: f })), {
|
|
586
|
+
format,
|
|
587
|
+
columns: [{ key: 'path', header: 'Path' }],
|
|
588
|
+
emptyMessage: 'No files matched',
|
|
589
|
+
}));
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (files.length === 0) {
|
|
593
|
+
console.log(chalk.yellow('No files matched'));
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
for (const file of files) {
|
|
597
|
+
console.log(file);
|
|
598
|
+
}
|
|
599
|
+
console.log();
|
|
600
|
+
console.log(chalk.gray(`${files.length} file(s) matched`));
|
|
601
|
+
}
|
|
602
|
+
catch (error) {
|
|
603
|
+
handleCommandError(error, spinner);
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
// Create directory
|
|
607
|
+
sandboxCommand
|
|
608
|
+
.command('mkdir <sandbox-id> <path>')
|
|
609
|
+
.description('Create a directory in a sandbox')
|
|
610
|
+
.option('-r, --recursive', 'Create parent directories as needed')
|
|
611
|
+
.action(async (sandboxId, path, options) => {
|
|
612
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
613
|
+
if (dryRunGuard(globalOpts, 'sandbox mkdir', {
|
|
614
|
+
'Sandbox ID': sandboxId,
|
|
615
|
+
Path: path,
|
|
616
|
+
Recursive: options.recursive ? 'yes' : 'no',
|
|
617
|
+
}))
|
|
618
|
+
return;
|
|
619
|
+
const spinner = ora(`Creating directory ${path}...`).start();
|
|
620
|
+
try {
|
|
621
|
+
const client = getClient();
|
|
622
|
+
await client.sandbox.mkdir(sandboxId, path, options.recursive);
|
|
623
|
+
spinner.succeed(`Directory created: ${path}`);
|
|
624
|
+
}
|
|
625
|
+
catch (error) {
|
|
626
|
+
handleCommandError(error, spinner, { mutationRecovery: workspaceRecovery });
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
// Remove file or directory
|
|
630
|
+
sandboxCommand
|
|
631
|
+
.command('rm <sandbox-id> <path>')
|
|
632
|
+
.description('Remove a file or directory from a sandbox')
|
|
633
|
+
.option('-r, --recursive', 'Remove directories recursively')
|
|
634
|
+
.option('-f, --force', 'Skip confirmation')
|
|
635
|
+
.action(async (sandboxId, path, options) => {
|
|
636
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
637
|
+
if (dryRunGuard(globalOpts, 'sandbox rm', {
|
|
638
|
+
'Sandbox ID': sandboxId,
|
|
639
|
+
Path: path,
|
|
640
|
+
Recursive: options.recursive ? 'yes' : 'no',
|
|
641
|
+
}))
|
|
642
|
+
return;
|
|
643
|
+
if (!options.force) {
|
|
644
|
+
const readline = await import('readline');
|
|
645
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
646
|
+
const answer = await new Promise((resolve) => {
|
|
647
|
+
rl.question(chalk.yellow(`Delete ${path}${options.recursive ? ' recursively' : ''}? [y/N] `), resolve);
|
|
648
|
+
});
|
|
649
|
+
rl.close();
|
|
650
|
+
if (answer.toLowerCase() !== 'y') {
|
|
651
|
+
console.log('Cancelled');
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
const spinner = ora(`Removing ${path}...`).start();
|
|
656
|
+
try {
|
|
657
|
+
const client = getClient();
|
|
658
|
+
await client.sandbox.deleteFile(sandboxId, path, options.recursive);
|
|
659
|
+
spinner.succeed(`Removed: ${path}`);
|
|
660
|
+
}
|
|
661
|
+
catch (error) {
|
|
662
|
+
handleCommandError(error, spinner, { mutationRecovery: workspaceRecovery });
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
// Move file
|
|
666
|
+
sandboxCommand
|
|
667
|
+
.command('mv <sandbox-id> <source> <destination>')
|
|
668
|
+
.description('Move or rename a file in a sandbox')
|
|
669
|
+
.action(async (sandboxId, source, destination) => {
|
|
670
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
671
|
+
if (dryRunGuard(globalOpts, 'sandbox mv', {
|
|
672
|
+
'Sandbox ID': sandboxId,
|
|
673
|
+
Source: source,
|
|
674
|
+
Destination: destination,
|
|
675
|
+
}))
|
|
676
|
+
return;
|
|
677
|
+
const spinner = ora(`Moving ${source} to ${destination}...`).start();
|
|
678
|
+
try {
|
|
679
|
+
const client = getClient();
|
|
680
|
+
await client.sandbox.moveFile(sandboxId, source, destination);
|
|
681
|
+
spinner.succeed(`Moved: ${source} -> ${destination}`);
|
|
682
|
+
}
|
|
683
|
+
catch (error) {
|
|
684
|
+
handleCommandError(error, spinner, { mutationRecovery: workspaceRecovery });
|
|
685
|
+
}
|
|
686
|
+
});
|
|
687
|
+
// Copy file
|
|
688
|
+
sandboxCommand
|
|
689
|
+
.command('cp <sandbox-id> <source> <destination>')
|
|
690
|
+
.description('Copy a file in a sandbox')
|
|
691
|
+
.action(async (sandboxId, source, destination) => {
|
|
692
|
+
const globalOpts = sandboxCommand.parent?.optsWithGlobals?.() ?? {};
|
|
693
|
+
if (dryRunGuard(globalOpts, 'sandbox cp', {
|
|
694
|
+
'Sandbox ID': sandboxId,
|
|
695
|
+
Source: source,
|
|
696
|
+
Destination: destination,
|
|
697
|
+
}))
|
|
698
|
+
return;
|
|
699
|
+
const spinner = ora(`Copying ${source} to ${destination}...`).start();
|
|
700
|
+
try {
|
|
701
|
+
const client = getClient();
|
|
702
|
+
await client.sandbox.copyFile(sandboxId, source, destination);
|
|
703
|
+
spinner.succeed(`Copied: ${source} -> ${destination}`);
|
|
704
|
+
}
|
|
705
|
+
catch (error) {
|
|
706
|
+
handleCommandError(error, spinner, { mutationRecovery: workspaceRecovery });
|
|
308
707
|
}
|
|
309
708
|
});
|
|
310
709
|
// Helper functions
|
|
@@ -313,11 +712,16 @@ function colorStatus(status) {
|
|
|
313
712
|
case 'running':
|
|
314
713
|
return chalk.green(status);
|
|
315
714
|
case 'creating':
|
|
715
|
+
case 'recovering':
|
|
716
|
+
case 'pausing':
|
|
717
|
+
case 'paused':
|
|
718
|
+
case 'resuming':
|
|
316
719
|
return chalk.yellow(status);
|
|
317
720
|
case 'terminated':
|
|
318
721
|
case 'terminating':
|
|
319
722
|
return chalk.gray(status);
|
|
320
723
|
case 'error':
|
|
724
|
+
case 'recovery_failed':
|
|
321
725
|
return chalk.red(status);
|
|
322
726
|
default:
|
|
323
727
|
return status;
|
|
@@ -366,4 +770,8 @@ function formatBudgetDuration(seconds) {
|
|
|
366
770
|
}
|
|
367
771
|
return `${clampedSeconds}s`;
|
|
368
772
|
}
|
|
773
|
+
// ps / logs / kill / spawn: supervised background processes
|
|
774
|
+
registerProcessCommands(sandboxCommand);
|
|
775
|
+
registerTimelineCommand(sandboxCommand);
|
|
776
|
+
registerSandboxEgressCommand(sandboxCommand);
|
|
369
777
|
//# sourceMappingURL=sandbox.js.map
|