boxd that every machine has.
It always asks first
remove --self always asks a yes/no question, and spells out that the target is the machine you are on:
y or yes deletes. Anything else (n, Enter, anything you didn’t mean as yes) leaves the machine running. If there is no answer at all, because stdin is closed, nothing is deleted and the command exits with an error.
There is no -y flag for --self. A script or an agent answers the question explicitly instead:
--json output on stdout stays clean.
From code: the SDKs
Code running inside a machine usesdelete_self (Python) or deleteSelf (TypeScript). The SDK finds the machine’s metadata adapter on its own, with no API key needed, and instead of a y/N question it takes the machine’s name as confirm, so the decision is spelled out in the code:
remove --self: confirm must be this machine’s name, or nothing is deleted and the call raises with the reason. Only the owner can do it, and never on a shared machine. Outside a machine, the call raises before doing anything. The async Python client has await boxd.machines.delete_self(confirm=...). In TypeScript it needs Node: the web entry can’t reach the metadata adapter.
It returns before the machine shuts down
The command gets its answer from boxd and exits0 first. The machine is deleted about 2 seconds later. That makes it safe as the last line of a job script. A line after it still runs, but only has those 2 seconds: enough for an exit or a quick notification, not for an upload.
Recipe: run a task, then delete
--auto-suspend-timeout 0 makes sure the machine stays awake. Auto-suspend is off by default, but a fork inherits its source’s setting, and a job with no network traffic on a machine that has it on goes into standby and stops making progress.
To delete only when the task succeeds, and keep a failed run’s machine around to debug, chain it:
Keep a delete-after timer as the safety net
Self-delete covers a task that finishes. A delete-after timer covers everything else: the task hangs, the script dies before its last line, or the deletion itself fails after the command has returned. Whichever comes first wins, so the machine never keeps running and billing.When it isn’t available
- Shared machines are refused: other members of your org depend on them. Delete them from outside with
boxd machine remove <name> -y, or from the console. - Only the machine’s owner can delete it this way.
- Isolated machines have no in-machine
boxd, so they can’t delete themselves. Give them a delete-after timer instead.
boxd machine remove <name> from inside a machine refuses to delete the machine it runs on and points you to --self, so you can’t delete yourself by naming yourself by accident.