Skip to content

The daemon

client.daemon reaches the daemon itself: its health and version, its settings, its log levels, the disk it uses, and the reports it gives for support. This page covers what a program reads to watch the daemon, and the few things it changes on it.

docs_src/client/daemon.py
import fastsandbox


async def main() -> None:
    client = await fastsandbox.connect()
    daemon = client.daemon
    health = await daemon.health()
    print(f"sbx {health.version}: healthy {health.is_healthy}")

    # The settings changed from their default, and where their value comes from.
    for setting in await daemon.settings():
        if setting.value != setting.default:
            print(f"{setting.key} = {setting.value} ({setting.source})")

    for target, level in (await daemon.log_levels()).items():
        print(f"log level of {target}: {level}")

    for summary in (await daemon.disk_usage()).summaries:
        print(f"{summary.resource_type}: {summary.size} bytes, {summary.reclaimable} reclaimable")


if __name__ == "__main__":
    fastsandbox.run(main())

Health and version

health() asks for the current Health: the status (is_healthy when it is healthy), the sbx release version and the api_version of the socket. Client.health keeps the one reported at connection time. info() gives the version and build information, the path of the API socket among them.

Settings

Call What it does
settings() every Setting: its key, value, default, source (default, override…), value_type (the type of the daemon) and description
setting(key) one setting
set_setting(key, value) overrides it with any JSON value, and returns the setting
unset_setting(key) removes the override: the default applies again

Warning

The settings are those of the user, shared by every sandbox and by the sbx CLI. A program that changes one restores it when it is done, also on an error: with unset_setting() when its source was default, with set_setting() and the previous value otherwise.

Log levels

log_levels() gives the level of each category, e.g. {"general": "info", "proxy": "info"}, and set_log_level(target, level) sets one: target is general, proxy or all, level is debug, info, warn or error. The levels are shared too: restore them.

Disk usage

disk_usage() gives a DiskUsage: a summary per resource type (images, containers, volumes), with the count, the count in use, the size and the size that could be reclaimed, in bytes, then the details of each resource as the daemon reports them.

Reports for support

debug_state() gives the internal state of the daemon, and diagnostics() the diagnostics it collects. Their shapes are not stable, and secrets show there as ***: read them for a support report, not for the logic of a program.

The resources of a sandbox

The CPUs and memory of a sandbox are set at its creation (cpus=2, memory="4g", see Creating a sandbox), and read back in its SandboxInfo; vm_metrics() gives the metrics of its virtual machine, in the Prometheus text format.