vm run --rm: ephemeral sandboxes

New `--rm` flag deletes the VM once the ssh session or `-- cmd`
exits, making `vm run` one-shot. Exit code from command mode still
propagates correctly.

Semantics:
- Create fails → no VM to delete, nothing to do.
- SSH-wait timeout → VM intentionally kept alive so `vm logs <name>`
  shows why; the timeout error already pointed users at that. Even
  with --rm, this path skips delete — a wedged sshd is exactly when
  you want post-mortem access.
- Session/command ends (any exit code, any reason) → VM is deleted
  via `vm.delete` RPC. Uses a fresh 10s context so Ctrl-C during the
  session doesn't abort the cleanup.

New vmDeleteFunc seam at the top of banger.go alongside the other
RPC seams. Two tests cover the happy path (session ends cleanly →
delete fires with correct ref) and the skip-on-timeout path (ssh
wait errors → delete does NOT fire).

README updated with an ephemeral example and a note about the
timeout-skip behaviour.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thales Maciel 2026-04-18 16:06:46 -03:00
parent 3aa64a63c1
commit b33f24865c
No known key found for this signature in database
GPG key ID: 33112E6833C34679
3 changed files with 142 additions and 3 deletions

View file

@ -43,6 +43,7 @@ One command, three modes:
banger vm run # bare sandbox — drops into ssh
banger vm run ./repo # workspace at /root/repo — drops into ssh
banger vm run ./repo -- make test # workspace + run command, exit with its status
banger vm run --rm -- script.sh # ephemeral: VM is deleted on exit
```
- Bare mode gives you a clean shell.
@ -54,10 +55,14 @@ banger vm run ./repo -- make test # workspace + run command, exit with its
propagates through `banger`.
Disconnecting from an interactive session leaves the VM running. Use
`vm stop` / `vm delete` to clean up.
`vm stop` / `vm delete` to clean up — or pass `--rm` so the VM
auto-deletes once the session / command exits.
`--branch` and `--from` apply only to workspace mode.
`--rm` delete is skipped when the initial ssh wait times out, so a
wedged sshd leaves the VM alive for `banger vm logs` inspection.
## Image catalog
`banger image pull <name>` resolves `<name>` in the embedded catalog