Failures and cleanup¶
What fails, how to tell why, and how to clean up after it without touching what is not yours. The errors page lists every error class; Troubleshooting goes symptom by symptom.
Errors you can act on¶
Every error of fastsandbox derives from
SandboxError, with an operation
that names what failed and a transient flag:
| Error | Usually | What to do |
|---|---|---|
DaemonUnavailableError |
The daemon is not running for this user, or the socket is elsewhere | sbx version as the same user; fastsandbox info prints the socket it tried |
UnsupportedVersionError |
sbx speaks an API version outside the supported range |
Upgrade fastsandbox or sbx; see Compatibility |
SandboxTimeoutError |
A deadline expired: after and operation say which |
See Timeouts and cancellation |
ConflictError |
A name already taken, a stopped sandbox, a sandbox replaced under the same name | Read code; hold a session while you work in a sandbox |
LaunchError |
A sandbox created, then failing to start, take its HTTP rules or its keys | step says which, kept whether it stays, __cause__ why |
CommandFailedError |
A command run with check=True exited with a non-zero code |
exit_code, stdout, stderr |
transient is true for connection failures, deadlines, answers 5xx and 409:
errors a later attempt may not meet. fastsandbox never retries by itself. A
program that retries should retry the whole step, a run or a block, rather
than one call, so that a new attempt starts from a sandbox it created.
When the cleanup fails¶
A block or a run whose removal fails keeps its own outcome:
- after an error, the error goes on with its own type, the failure of the
removal noted on it (
__notes__) and logged as a warning; - after a success, the failure is raised, except by a run, which logs it as
a warning on the logger of its task,
fastsandbox.task.<name>, and returns its result.
The note and the warning name the sandbox and its identifier. The command line prints an error followed by its notes, and its logging prints the warning on standard error.
Finding what was left¶
A sandbox stays after a killed process, a second Ctrl-C during a cleanup, a
failed removal, or a task with keep=True. List the sandboxes of your user:
The names fastsandbox gives:
| Created by | Name |
|---|---|
client.create(), spec.launch() without a name |
fastsandbox- and 8 hexadecimal digits |
| A run of a task | <application>-<task>- and 8 hexadecimal digits, lowercase, dashes for other characters; an application named fastsandbox gives names that start like the previous line |
A kit compiled with sbx |
sbx-kit-compile-<pid>-<n>, left only when a compilation is cut short: by its own timeout, a killed process, or an exit that stops waiting for it; one given up otherwise finishes, then removes it |
fastsandbox sets no label. A name with a known prefix may still belong to a
run in progress in another process: look at status and created_at before
you remove it.
Removing a sandbox safely¶
Remove a sandbox only if it is still the one you saw: give its identifier,
and the daemon refuses with a
ConflictError if another sandbox has
taken the name since. This program removes the stopped sandboxes whose name
starts with a prefix, such as ci-run-tests- for the runs of the task
run_tests of the application ci:
import sys
import fastsandbox
from fastsandbox.models import SandboxState
async def main(prefix: str) -> None:
client = await fastsandbox.connect()
for info in await client.sandboxes.list():
# Only the stopped sandboxes named as your runs name theirs.
if not info.name.startswith(prefix) or info.status != SandboxState.STOPPED:
continue
print(f"removing {info.name}, created {info.created_at}")
# Refused with a ConflictError if another sandbox took the name since.
await client.sandbox(info.name).delete(force=True, expected_id=info.id)
if __name__ == "__main__":
fastsandbox.run(main(sys.argv[1]))
sbx rm NAME removes by name. Never remove a sandbox you did not create:
the daemon holds those of every program of your user. sbx prune, which
removes every stopped sandbox, is no tool for a shared machine.
What else may be left:
- Network rules of an abandoned creation: a creation cut short can leave
the kit rules of its name, which
sbx policy rmrefuses; they go when a sandbox of that name is created and removed. - Images: the images kits pulled or loaded stay in the image store of
the daemon, where the next sandboxes reuse them;
client.images.remove()removes one. - Kit packages in the directory of a kit cache, when one was given: remove the directory to forge them again.
When the daemon restarts¶
What happens to sandboxes over a restart of the daemon was not measured.
Requests under way fail, with
DaemonUnavailableError or
an ApiError; a session the daemon closes is reopened, with a growing delay,
until it is released. After a restart, list the sandboxes and remove those
your runs left.
Next¶
- Sandbox lifecycle: who removes a sandbox, in every case.
- Logging and observability: what fastsandbox logs.
- Errors: every error class.