serbox

    Self-hosted Linux boxes for agents, like instabox but on your own server

    sandbox
    box
    docker
    agent
    linux
    cli
    Download zip
    Author
    Version
    0.1.2
    License
    Apache-2.0
    Last updated
    yesterday
    Downloads
    24

    #serbox

    Linux boxes for agents — on your own server.

    serbox creates small, disposable Docker boxes on the machine it runs on, then gives you one command to run things inside them, copy files in and out, pause them, snapshot them and forward their ports. No account, no API key, no control plane: the server you already have is the control plane.

    It is the local counterpart of instabox: the same box workflow, without the hosted service.

    npx @tomasko/serbox create --name dev npx @tomasko/serbox exec dev -- 'apt-get update && apt-get install -y ripgrep' npx @tomasko/serbox ssh dev npx @tomasko/serbox rm dev --yes

    #Install

    npm install -g @tomasko/serbox # or: npx @tomasko/serbox ...

    The npm package is a launcher. It downloads the matching static binary from GitHub Releases on first run into ~/.cache/serbox, verifies its SHA-256 and execs it. Works under --ignore-scripts, pnpm and npx because there is no install script.

    Other ways:

    # install script curl -LsSf https://raw.githubusercontent.com/tomasky/serbox/main/install.sh | bash # from source (MoonBit) moon build --target native --release ./_build/native/release/build/cmd/main/main.exe version

    Supported targets: linux-x86_64, linux-aarch64. serbox is meant to run on the Linux server that owns the boxes; on macOS use a Linux VM or Docker Desktop's Linux engine.

    #Requirements

    • Linux with Docker (the docker CLI and a reachable daemon)
    • Permission to talk to the daemon (docker group or root)
    • Nothing else — no Python, no runtime, no account

    serbox doctor checks all of this and says what is missing.

    #A box in one minute

    serbox create --name dev --template node # pull image, start container serbox exec dev -- 'node --version' # one command, exit code preserved serbox ssh dev # interactive shell serbox push dev ./src /data/src # copy in serbox pull dev /data/out.log ./out.log # copy out serbox suspend dev # pause (frees CPU, keeps disk) serbox resume dev # unpause serbox snapshot save dev --name ready # commit the box to an image serbox create --name dev2 --snapshot ready # start another box from it serbox port publish dev 3000 --host 3000 # expose a port on this server serbox rm dev --yes

    Boxes keep their files under /data ($HOME is /data/home), so push, pull and snapshots have one predictable place to work with.

    #What a box is

    • a Docker container named serbox-<box>, labelled serbox.managed=1
    • running sleep infinity so exec can attach any time
    • created from a template image (default is debian:bookworm-slim; also ubuntu, alpine, node, python, go, rust, agent)
    • described by a small JSON file in ~/.serbox/boxes/, so ls, gc and doctor work even after a reboot

    Isolation is Docker's: namespaces, cgroups and the container's own filesystem. Boxes share the host kernel. Anyone who can run docker can read every box on the machine, so serbox is for a server you already trust, not for untrusted multi-tenant hosting.

    #One CLI, many servers

    A box lives on one Linux host, but you do not have to sit on that host. Run a small daemon there once, register it on your laptop, and every command works against it — including from a laptop that has no Docker at all.

    On the server (once):

    serbox serve --ensure # start on 127.0.0.1:7373, prints the token serbox serve --print-token # show the token later

    On your laptop:

    # uses ssh: checks/installs serbox on the server, starts the daemon, # opens a local tunnel and stores a per-host token serbox host add prod me@prod.example.com serbox host use prod # make it the default serbox create --name dev --template node serbox exec dev -- 'node --version' serbox ssh dev # ssh -t through the server serbox host use local # back to this machine

    serbox -H prod ls pins one command to a host without changing the default. serbox host ls lists hosts with their state and current marker; serbox hostrm prod forgets one. Tunnels are started on demand and reused.

    Each host keeps its own token in ~/.serbox/hosts.json (mode 0600), so servers never share credentials and switching is just host use. Rotate a server's token with serbox serve --rotate-token on that server; clients re-authorize with serbox host add NAME ... --force.

    Rules for a host added by ssh: it needs ssh and either the serbox binary in PATH or --install (which runs install.sh). An air-gapped or pre-tunnelled server can be registered directly:

    serbox host add prod --address 127.0.0.1:7373 --token TOKEN

    exec, ls, create, snapshots, jobs, ports and the rest are served by the daemon; exit codes and --json come back unchanged. push and pull also work over ssh because they touch your local disk — those two commands need the host to have been added by ssh, not --address.

    Security: the daemon speaks plain HTTP on loopback by default and authenticates every request with a 32-hex-character token. Reach it through ssh (host add), a private network, or a TLS terminator; never expose the port to the internet. Anyone with the token can run commands in your boxes.

    #Commands

    commandwhat it does
    create --name N [--template T] [--env K=V] [--publish P] [--setup-file F]start a box
    ls, get Nlist / inspect boxes
    exec N -- CMDrun a command (--timeout, --stream, --background, --json)
    ssh Ninteractive shell
    push, pull, cp, files N PATHmove files, list or cat them
    suspend / resume, start / stop, restartlifecycle
    snapshot save/ls/rm/restore/import, fork Nimages and copies
    port publish/unpublish/lsforward a box port to this server
    secrets set/ls/rm/select/pushkeep credentials out of command lines
    auto-suspend N 30m, max-run N 2h, gcidle cleanup
    run -- CMDcreate, run, delete in one step (--keep to keep)
    jobs ls/logs/wait/killbackground commands started by exec --background
    ps, history, output, disk, metrics, logslook inside
    templates, usage, doctor, completion, updatehost and shell help
    skills list/installinstall the bundled agent skills
    serve, host add/ls/use/current/rmrun and use boxes on other servers

    Global flags: -H/--remote HOST, --json (-o json), --no-color.

    #Piping and exit codes

    One argument is run through the box's shell, several arguments are an exact argv with no shell:

    serbox exec dev -- 'echo $HOME && ls /data' # shell serbox exec dev -- printf '%s\n' 'a b' # argv

    Exit codes follow the documented contract: 2 usage, 4 not found, 75 retryable, 124 timeout, 130 interrupted, anything else is the command's own status. --json prints {"error":{"code","message"}} on stdout and one human line on stderr, so scripts can parse stdout without losing the reason.

    #Agent skills

    serbox skills list # what ships in the binary serbox skills install -y # every skill, every agent it finds serbox skills install --target claude,codex serbox skills install --only serbox-snapshots -y

    Four complete skills ship inside the binary (and in the npm package):

    SkillCovers
    serboxcreate, exec, files, jobs, ports, pause, remote hosts
    serbox-snapshotssave, restore, fork, import and delete snapshots
    serbox-move-repocopy a git checkout, its worktrees and uncommitted work into a box, then install dependencies
    serbox-basic-setupstore tokens as secrets, copy git and editor config, verify what still needs a manual step

    Each installs as a directory with SKILL.md and any helper scripts (scripts/repo-files.mjs, scripts/deps.sh, ...), so an agent has the exact commands without network access. A skill you wrote yourself (one without the installed-by: serbox marker) is never overwritten.

    #Secrets

    serbox secrets set GITHUB_TOKEN # reads the value from stdin serbox create --name dev --secrets GITHUB_TOKEN serbox exec dev -- 'gh auth status' # value is in the environment

    Values live in ~/.serbox/secrets.json (mode 0600) and are passed to the container as environment variables. secrets push writes them to /data/.serbox/secrets.env inside the box for tools that read a file.

    #Host state

    Everything lives in ~/.serbox (override with SERBOX_HOME):

    boxes/ one JSON file per box snapshots/ snapshot metadata jobs/ background job metadata history/ per-box command history ports/ published port records secrets.json credentials (0600)

    Deleting that directory loses serbox's view of the boxes, not the containers; serbox doctor and docker ps -a --filter label=serbox.managed=1 help recover.

    #How it differs from instabox

    serboxinstabox
    where boxes runthe server you run it oninstabox's cloud
    accountnonesign in / API key
    isolationDocker on your kernelmicroVM
    snapshotsdocker commit imagesVM snapshots
    port URLsyour server's host and portpublic URLs
    offlineyes (after images are pulled)no

    Use serbox when you have a Linux box and want the workflow without the service. Use instabox when you want someone else to run the machines.

    #Development

    moon test --target native # unit tests (no docker needed) moon build --target native --release node --test npmjs/ # npm launcher tests scripts/build-linux-static.sh # static musl binary in dist/

    An end-to-end check that needs Docker:

    SERBOX_HOME=$(mktemp -d) scripts/test-e2e.sh ./_build/native/release/build/cmd/main/main.exe

    #Publishing

    Releases are cut from a tag:

    # bump the version in moon.mod, serbox.mbt and npmjs/package.json git tag v0.1.1 && git push origin v0.1.1

    The release workflow builds both static Linux binaries, publishes a GitHub release with .sha256 files, then publishes npmjs/ to npm when the NPM_TOKEN secret is set. To publish by hand:

    cd npmjs && npm publish --access public

    #License

    Apache-2.0.

    CliError

    pub suberror CliError {
    Usage(String)
    Failed(Int, String)
    }

    A command failure. Usage errors are separated from everything else because they exit 2 and print the help hint.

    Args

    pub struct Args {
    positional : Array[String]
    values : Map[String, Array[String]]
    bools : Map[String, Bool]
    rest : Array[String]
    }

    Flags a command takes: which ones carry a value and which are switches. Anything else is a usage error, so a typo never becomes a silently ignored argument.

    Args::all

    fn Args::all(self : Args, name : String) -> Array[String]

    Args::arg

    fn Args::arg(self : Args, index : Int, what : String) -> String raise

    Args::arg_opt

    fn Args::arg_opt(self : Args, index : Int) -> String?

    Args::flag

    fn Args::flag(self : Args, name : String) -> Bool

    Args::need

    fn Args::need(self : Args, name : String) -> String raise

    Args::value

    fn Args::value(self : Args, name : String) -> String?

    BoxConfig

    pub(all) struct BoxConfig {
    name : String
    template : String
    image : String
    shell : String
    created_at : Int64
    env : Map[String, String]
    meta : Map[String, String]
    ports : Array[PortMap]
    secrets : Array[String]
    auto_suspend_secs : Int64
    max_run_secs : Int64
    paused_by : String
    last_used_at : Int64
    running_since : Int64
    delete_at : Int64
    setup_exit : Int
    } derive(
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    Everything serbox remembers about a box.

    Check

    pub struct Check {
    name : String
    ok : Bool
    detail : String
    }

    One diagnostic line.

    CreateOptions

    pub struct CreateOptions {
    name : String
    template : String
    image : String
    env : Map[String, String]
    meta : Map[String, String]
    ports : Array[PortMap]
    secrets : Array[String]
    auto_suspend_secs : Int64
    delete_at : Int64
    }

    What every path that creates a box needs. Kept in one struct so create and run cannot drift apart.

    DockerResult

    pub struct DockerResult {
    code : Int
    out : String
    err : String
    }

    The result of a captured command: status, standard output and standard error, already decoded. Docker's output is UTF-8 on every version serbox supports, and undecodable bytes become U+FFFD rather than an error.

    HistoryEntry

    pub(all) struct HistoryEntry {
    id : String
    command : String
    exit_code : Int
    started_at : Int64
    duration_ms : Int64
    stdout_text : String
    stderr_text : String
    } derive(
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    One exec that ran, newest last, for serbox history.

    HostRecord

    pub(all) struct HostRecord {
    name : String
    target : String
    remote_bin : String
    remote_port : Int
    local_port : Int
    token : String
    tunnel_pid : Int
    created_at : Int64
    } derive(
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    A server this CLI can drive remotely: the SSH target used to reach it, the daemon port on that server, and the token that daemon requires.

    The token is as sensitive as an SSH key: anyone holding it can run any serbox command on that server. hosts.json is therefore written 0600.

    Job

    pub(all) struct Job {
    id : String
    box : String
    command : String
    started_at : Int64
    pid : Int
    } derive(
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    A detached command started with exec --background.

    PortForward

    pub(all) struct PortForward {
    box : String
    container : Int
    host : Int
    pid : Int
    created_at : Int64
    } derive(
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    A published port: a detached forwarder on the host, from a host port to a port inside a box.

    PortMap

    One published port: a host port on the server, forwarded to a port inside the box.

    SkillFile

    pub struct SkillFile {
    skill : String
    path : String
    body : String
    }

    One file of a bundled skill, relative to the skill's own directory.

    SkillTarget

    pub struct SkillTarget {
    name : String
    dirs : Array[String]
    }

    One place a skill can be installed, and the flag that names it.

    Snapshot

    pub(all) struct Snapshot {
    name : String
    image : String
    source : String
    created_at : Int64
    description : String
    } derive(
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    A saved copy of a box's filesystem.

    DEFAULT_SERVE_PORT

    let DEFAULT_SERVE_PORT : Int

    all_boxes

    async fn all_boxes() -> Array[BoxConfig]

    Every box record on this host, oldest first.

    all_hosts

    async fn all_hosts() -> Array[HostRecord]

    all_jobs

    async fn all_jobs(box : String) -> Array[Job]

    All job records of a box, newest first.

    all_port_forwards

    async fn all_port_forwards() -> Array[PortForward]

    all_snapshots

    async fn all_snapshots() -> Array[Snapshot]

    allocate_host_port

    async fn allocate_host_port(preferred : Int) -> Int

    Pick a host port: the requested one when it is free, otherwise the first free port at or above 10000.

    ascii_lowercase

    fn ascii_lowercase(text : String) -> String

    ASCII lowercase, for prompts where the answer is y/yes.

    bold

    fn bold(text : String) -> String

    box_blocked_reason

    async fn box_blocked_reason(config : BoxConfig, wake : Bool) -> String?

    The reason a command cannot touch a box, or None when it can.

    wake=true revives a box that paused itself, which is instabox's rule: idle pauses are transparent, a pause the user asked for is not.

    box_config_path

    fn box_config_path(name : String) -> String

    box_data_root

    let box_data_root : String

    Where a box keeps its files, the way instabox keeps /data.

    box_home

    let box_home : String

    HOME inside a box, under the persistent data directory.

    box_mkdir_p

    async fn box_mkdir_p(box : String, path : String) -> Unit

    mkdir -p inside a box.

    box_path_exists

    async fn box_path_exists(box : String, path : String) -> Bool

    Whether a path inside a box exists.

    box_path_is_dir

    async fn box_path_is_dir(box : String, path : String) -> Bool

    Whether a path inside a box is a directory.

    box_shell

    let box_shell : String

    What serbox exec runs a shell string with.

    boxes_dir

    fn boxes_dir() -> String

    bundled_skill_files

    fn bundled_skill_files() -> Array[SkillFile]

    bundled_skill_names

    fn bundled_skill_names() -> Array[String]

    The skill directories this binary carries, in name order.

    cmd_auto_suspend

    async fn cmd_auto_suspend(args : Args) -> Unit

    serbox auto-suspend BOX DURATION|0

    cmd_completion

    async fn cmd_completion(args : Args) -> Unit

    serbox completion bash|zsh|fish

    cmd_cp

    async fn cmd_cp(args : Args) -> Unit

    serbox cp [-r] SRC DST, where either side may be BOX:/path.

    cmd_create

    async fn cmd_create(args : Args) -> Unit

    serbox create

    cmd_disk

    async fn cmd_disk(args : Args) -> Unit

    serbox disk

    cmd_doctor

    async fn cmd_doctor(args : Args) -> Unit

    serbox doctor: the host's prerequisites, in the order they break.

    cmd_exec

    async fn cmd_exec(args : Args) -> Unit

    serbox exec

    cmd_files

    async fn cmd_files(args : Args) -> Unit

    serbox files BOX [PATH]: list a directory, print a text file.

    cmd_fork

    async fn cmd_fork(args : Args) -> Unit

    serbox fork BOX [--count N] [--name N]

    cmd_gc

    async fn cmd_gc(args : Args) -> Unit

    serbox gc: pause what has been idle and delete what was due.

    serbox ships no daemon of its own, so this is the one command that has to run on a timer — serbox gc from cron once a minute is all a host needs.

    cmd_get

    async fn cmd_get(args : Args) -> Unit

    serbox get

    cmd_history

    async fn cmd_history(args : Args) -> Unit

    serbox history

    cmd_host_add

    async fn cmd_host_add(args : Args) -> Unit

    serbox host add NAME USER@HOST [--port N] [--install]

    cmd_host_current

    async fn cmd_host_current(_args : Args) -> Unit

    serbox host current

    cmd_host_ls

    async fn cmd_host_ls(_args : Args) -> Unit

    serbox host ls

    cmd_host_rm

    async fn cmd_host_rm(args : Args) -> Unit

    serbox host rm NAME

    cmd_host_use

    async fn cmd_host_use(args : Args) -> Unit

    serbox host use NAME|local

    cmd_jobs

    async fn cmd_jobs(args : Args) -> Unit

    serbox jobs

    cmd_lifecycle

    async fn cmd_lifecycle(command : String, args : Args) -> Unit

    serbox start|stop|suspend|resume|restart|wake

    cmd_logs

    async fn cmd_logs(args : Args) -> Unit

    serbox logs

    cmd_ls

    async fn cmd_ls(args : Args) -> Unit

    serbox ls

    cmd_max_run

    async fn cmd_max_run(args : Args) -> Unit

    serbox max-run BOX MINUTES

    cmd_metrics

    async fn cmd_metrics(args : Args) -> Unit

    serbox metrics: one Docker stats sample.

    cmd_output

    async fn cmd_output(args : Args) -> Unit

    serbox output: the last command's stored output.

    cmd_port

    async fn cmd_port(args : Args) -> Unit

    serbox port publish|ls|unpublish|setup

    cmd_ps

    async fn cmd_ps(args : Args) -> Unit

    serbox ps

    cmd_pull

    async fn cmd_pull(args : Args) -> Unit

    serbox pull BOX REMOTE [LOCAL]

    cmd_push

    async fn cmd_push(args : Args) -> Unit

    serbox push BOX LOCAL [REMOTE]

    cmd_rename

    async fn cmd_rename(args : Args) -> Unit

    serbox rename

    cmd_resize

    async fn cmd_resize(args : Args) -> Unit

    serbox resize BOX --cpus N --memory M

    cmd_rm

    async fn cmd_rm(args : Args) -> Unit

    serbox rm

    cmd_run

    async fn cmd_run(args : Args) -> Unit

    serbox run: create a box, run one command, delete the box.

    cmd_secrets

    async fn cmd_secrets(args : Args) -> Unit

    serbox secrets

    cmd_serve

    async fn cmd_serve(args : Args) -> Unit

    serbox serve [--port N] [--bind ADDR] [--ensure] [--daemon] [--print-token]

    cmd_skills

    async fn cmd_skills(args : Args) -> Unit

    serbox skills

    cmd_snapshot

    async fn cmd_snapshot(args : Args) -> Unit

    serbox snapshot

    cmd_ssh

    async fn cmd_ssh(args : Args) -> Unit

    serbox ssh (and shell): a login shell, or a command over it.

    cmd_templates

    async fn cmd_templates() -> Unit

    serbox templates

    cmd_update

    async fn cmd_update(args : Args) -> Unit

    serbox update: the npm package is the distribution channel, so updating is npm's job rather than a self-rewriting binary.

    cmd_usage

    async fn cmd_usage() -> Unit

    serbox usage

    cmd_version

    async fn cmd_version() -> Unit

    The version command, also used by the npm launcher's smoke test.

    colors_enabled

    fn colors_enabled() -> Bool

    Colors on, unless NO_COLOR is set or stdout is not a terminal.

    command_argv

    fn command_argv(args : Args) -> Array[String]

    The command a command line asked for: everything after --, or the positionals after the ones the command consumed.

    commit_container

    async fn commit_container(box : String, image : String) -> DockerResult

    Save a container's filesystem as an image.

    compact_time

    fn compact_time(epoch : Int64) -> String

    20261125-0430 in UTC, the shape instabox uses for snapshot names.

    confirm

    async fn confirm(question : String) -> Bool

    Ask y/N on a terminal. Off a terminal the answer is no: destructive commands need --yes, so a pipe cannot delete a box by accident.

    container_exists

    async fn container_exists(box : String) -> Bool

    Whether a box's container exists at all.

    container_ip

    async fn container_ip(box : String) -> String?

    The host path Docker exposes a container's root filesystem at (an overlay mount). Used only for reading metrics and, when available, nothing else.

    container_logs

    async fn container_logs(box : String, tail : Int, follow : Bool) -> Int

    A box's console output, tail lines or everything.

    container_name

    fn container_name(box : String) -> String

    The container serbox uses for a box.

    container_prefix

    let container_prefix : String

    Prefix of every Docker container serbox owns. A container outside this prefix is never touched, so serbox can share a host with other tools.

    container_state

    async fn container_state(box : String) -> String

    running, paused, exited, created, restarting or missing.

    container_stats

    async fn container_stats(box : String) ->
    Json
    ?

    docker stats for one container, as JSON. None when the container is not running, which is also when Docker cannot sample it.

    container_top

    async fn container_top(box : String, all : Bool) -> DockerResult

    The container's processes, as docker top prints them.

    copies_contents

    fn copies_contents(path : String) -> Bool

    Whether a source argument means "the contents of this directory".

    copy_in

    async fn copy_in(box : String, host_path : String, remote : String) -> DockerResult

    docker cp a host path into a box.

    copy_out

    async fn copy_out(box : String, remote : String, host_path : String) -> DockerResult

    docker cp a path out of a box.

    create_box

    async fn create_box(options : CreateOptions) -> BoxConfig

    current_host

    async fn current_host() -> String

    The host -H falls back to. "" means local: commands run on this machine, exactly as before a host was added.

    current_host_path

    fn current_host_path() -> String

    default_template

    let default_template : String

    The default template and the image it starts from.

    default is a bare Debian like instabox's Linux machines: bash, coreutils, git and curl, which is enough for an agent to install what it needs.

    delete_box_config

    async fn delete_box_config(name : String) -> Unit

    delete_host

    async fn delete_host(name : String) -> Bool

    delete_snapshot_config

    async fn delete_snapshot_config(name : String) -> Unit

    dim

    fn dim(text : String) -> String

    display_state

    fn display_state(container_state : String, paused_by : String) -> String

    The state a user sees, combining Docker's state with serbox's own.

    auto-paused is a paused box that paused itself and would resume on the next command; paused and stopped are the user's own decisions.

    docker_available

    async fn docker_available() -> Bool

    Whether the Docker daemon answers.

    docker_capture

    async fn docker_capture(args : Array[String]) -> DockerResult

    Run docker <args> and collect its output.

    docker_inherit

    async fn docker_inherit(args : Array[String]) -> Int

    Run docker <args> with this process's stdio, so pull progress and interactive shells reach the terminal.

    eline

    async fn eline(text : String) -> Unit

    ensure_dir

    async fn ensure_dir(path : String) -> Unit

    mkdir -p.

    ensure_image

    async fn ensure_image(image : String) -> Bool

    Ensure image is present, pulling it when it is not.

    error_code_name

    fn error_code_name(code : Int) -> String

    The name an exit code carries in --json errors.

    exec_argv

    fn exec_argv(command : Array[String], timeout_secs : Int64?, shell? : String) -> Array[String]

    The argv to hand docker exec for a command line: one argument is a shell string run through bash -lc (instabox's rule, and the only form that supports pipes and redirection), several are an exact argv with no shell.

    exec_box_batch

    async fn exec_box_batch(box : String, command : Array[String], cwd : String?, env : Map[String, String], timeout_secs : Int64?, shell? : String) -> Int

    Run a command in a box with inherited stdio and no history entry. Returns the command's exit status.

    exec_command_of

    fn exec_command_of(args : Args) -> Array[String]

    The command line a serbox exec invocation asked for.

    exec_in_box

    async fn exec_in_box(box : String, argv : Array[String], cwd : String?, env : Map[String, String], stdin : Bool) -> Int

    docker exec into a box, with the flags that make a command behave like a login shell would: the persistent HOME, a working directory and the box's environment.

    exec_in_box_capture

    async fn exec_in_box_capture(box : String, argv : Array[String]) -> DockerResult

    docker exec with captured output.

    exec_in_box_capture_argv

    async fn exec_in_box_capture_argv(box : String, argv : Array[String], cwd : String?, env : Map[String, String], stdin : Bool) -> DockerResult

    docker exec with cwd/env/stdin, captured.

    format_age

    fn format_age(seconds : Int64) -> String

    How long ago a past timestamp was, as 3s, 12m, 4h, 2d.

    format_duration

    fn format_duration(secs : Int64) -> String

    90s → 1m30s, 7200s → 2h. Compact and unambiguous.

    format_size

    fn format_size(bytes : Int64) -> String

    Clamp a large byte count to a short human string (12.4 MiB).

    generate_box_name

    fn generate_box_name(prefix : String) -> String

    A short, unique box name for commands that do not ask for one.

    green

    fn green(text : String) -> String

    hex_decode

    fn hex_decode(text : String) -> Bytes?

    The inverse of hex_encode; None for odd length or a non-hex digit.

    hex_encode

    fn hex_encode(data : Bytes) -> String

    Lowercase hex, for the remote protocol: JSON carries text, and command output is arbitrary bytes, so every byte goes over as two hex digits.

    history_dir

    fn history_dir() -> String

    host_name

    fn host_name() -> String

    The host a published URL points at: SERBOX_HOST, else the machine's own hostname.

    host_path_is_dir

    async fn host_path_is_dir(path : String) -> Bool

    Whether a host path is a directory.

    hosts_path

    fn hosts_path() -> String

    image_exists

    async fn image_exists(image : String) -> Bool

    Whether an image is present locally.

    job_exit_code

    async fn job_exit_code(box : String, job_id : String) -> Int?

    The job's exit code, or None while it still runs.

    job_log_path

    fn job_log_path(job_id : String) -> String

    The in-container path of a job's files.

    job_pid

    async fn job_pid(box : String, job_id : String) -> Int

    jobs_dir

    fn jobs_dir() -> String

    json_only

    async fn json_only(value :
    Json
    ) -> Bool

    Print a value as JSON when --json is on. Commands that would otherwise print a table call this and then the table only when it returns false.

    json_requested

    fn json_requested() -> Bool

    line

    async fn line(text : String) -> Unit

    list_dir

    async fn list_dir(path : String) -> Array[String]

    Directory entry names, sorted, without the ./.. noise. [] for a directory that does not exist.

    load_box

    async fn load_box(name : String) -> BoxConfig?

    load_box_or_fail

    async fn load_box_or_fail(name : String) -> BoxConfig

    load_host

    async fn load_host(name : String) -> HostRecord?

    load_port_forward

    async fn load_port_forward(box : String, container_port : Int) -> PortForward?

    load_secrets

    async fn load_secrets() -> Map[String, String]

    Every stored secret. A missing or unreadable file is an empty store, not an error: secrets are optional.

    load_snapshot

    async fn load_snapshot(name : String) -> Snapshot?

    local_port_open

    async fn local_port_open(port : Int) -> Bool

    Whether something accepts connections on 127.0.0.1:port.

    main_cli

    async fn main_cli() -> Unit

    Entry point of the serbox binary.

    new_box_config

    fn new_box_config(name : String, template : String, image : String) -> BoxConfig

    The record a freshly created box starts from.

    now_secs

    fn now_secs() -> Int64

    Current time in Unix seconds.

    out

    async fn out(text : String) -> Unit

    pad_left

    fn pad_left(text : String, width : Int) -> String

    pad_right

    fn pad_right(text : String, width : Int) -> String

    Pad text on the right to width display columns (ASCII-safe; box names, states and ports are all ASCII).

    parse_args

    fn parse_args(raw : Array[String], value_flags : Array[String], bool_flags : Array[String]) -> Args raise

    parse_assignment

    fn parse_assignment(text : String, flag : String) -> (String, String) raise

    KEY=VALUE from a flag, or a usage error.

    parse_duration

    fn parse_duration(text : String, default_unit_secs? : Int64) -> Int64?

    Parse a duration such as 30m, 2h, 45s, 1h30m or 0.

    Bare digits mean minutes where a command documents minutes (max-run), so callers that want seconds pass default_unit_secs=1; 0 always means off.

    parse_port

    fn parse_port(text : String) -> Int raise

    parse_publish

    fn parse_publish(text : String) -> PortMap raise

    Parse a --publish value: 8080 publishes 8080 on the host, 8080:18080 maps box port 8080 to host 18080.

    path_basename

    fn path_basename(path : String) -> String

    Everything after the last /, or the whole path.

    path_dirname

    fn path_dirname(path : String) -> String

    Everything before the last /, or . when there is none.

    path_join

    fn path_join(left : String, right : String) -> String

    One path segment below another, with no doubled slash.

    pause_container

    async fn pause_container(box : String) -> DockerResult

    Pause a container: memory and processes are kept, exactly instabox's suspend.

    port_free

    async fn port_free(port : Int) -> Bool

    Whether a port is free to bind on this host.

    port_record_path

    fn port_record_path(box : String, container_port : Int) -> String

    ports_dir

    fn ports_dir() -> String

    async fn print_command_help(command : String) -> Unit

    Per-command help, so serbox help exec is the same as serbox exec --help.
    async fn print_usage() -> Unit

    Print the top-level help. Kept short: one line per command group, with the details behind serbox help <command>.

    publish_port

    async fn publish_port(config : BoxConfig, container_port : Int, host_port : Int, bind : String) -> PortForward

    Start the detached forwarder and record it.

    pull_image

    async fn pull_image(image : String) -> Bool

    Pull an image, showing progress on stderr the way Docker prints it.

    pull_path

    async fn pull_path(box : String, remote : String, host_path : String?) -> Unit

    Copy a path out of a box.

    push_path

    async fn push_path(box : String, host_path : String, remote : String?, parents : Bool) -> Unit

    Push a host path into a box.

    read_env_file

    async fn read_env_file(path : String) -> Map[String, String]

    Read a .env-style file: one KEY=VALUE per line, # comments and blank lines ignored.

    read_history

    async fn read_history(box : String, limit : Int) -> Array[HistoryEntry]

    The stored history of a box, newest first, at most limit entries.

    read_lines

    async fn read_lines(path : String) -> Array[String]

    Read a whole file's lines, [] when absent.

    read_text

    async fn read_text(path : String) -> String?

    Read a UTF-8 file, or None when it does not exist or cannot be read.

    record_history

    async fn record_history(box : String, entry : HistoryEntry) -> Unit

    Append one entry to a box's history, keeping the newest 200 entries.

    red

    fn red(text : String) -> String

    remote_run

    async fn remote_run(host_name : String, argv : Array[String]) -> Int

    Send one request to a host's daemon and stream the result. Returns the exit code, so a remote exec exits exactly like a local one.

    remove_container

    async fn remove_container(box : String) -> DockerResult

    Delete the container and everything in it. Snapshots taken from it stay.

    remove_image

    async fn remove_image(image : String) -> DockerResult

    Remove an image.

    render_table

    fn render_table(headers : Array[String], rows : Array[Array[String]]) -> String

    Render a simple table with a header, the shape instabox ls uses.

    require_box

    async fn require_box(name : String) -> BoxConfig?

    Load a box or report the exact command that creates one.

    require_usable

    async fn require_usable(config : BoxConfig, wake : Bool) -> Unit

    Refuse a command against a box that cannot take it, with the exact command that fixes the state. wake transparently resumes an auto-pause.

    restart_container

    async fn restart_container(box : String) -> DockerResult

    Power-cycle a container.

    run_container

    async fn run_container(box : String, image : String, args : Array[String]) -> DockerResult

    Start a box's container from a block of docker run flags.

    args holds everything between docker run and the image, so callers decide the ports and environment and this stays one place where the container's identity is fixed.

    run_forwarder

    async fn run_forwarder(box : String, host_port : Int, container_port : Int, bind : String) -> Unit

    RFD 6455-free TCP relay: accept on host_port, connect to the container's address, splice both directions.

    run_setup_file

    async fn run_setup_file(config : BoxConfig, path : String, quiet : Bool) -> Unit

    Run a setup script inside a box: copy it in, run it with bash, record the exit status. A failed script keeps the box, as instabox's does.

    save_box

    async fn save_box(config : BoxConfig) -> Unit

    save_hosts

    async fn save_hosts(hosts : Array[HostRecord]) -> Unit

    save_port_forward

    async fn save_port_forward(forward : PortForward) -> Unit

    save_snapshot

    async fn save_snapshot(snapshot : Snapshot) -> Unit

    secrets_names

    async fn secrets_names() -> Array[String]

    secrets_path

    fn secrets_path() -> String

    self_exe

    async fn self_exe() -> String

    The executable to re-launch for a forwarder: /proc/self/exe, so the npm launcher's downloaded binary is used rather than whatever is on PATH.

    serbox_echo

    fn serbox_echo(on : Int) -> Unit

    FFI: toggle terminal echo, for a secret typed at a prompt.

    serbox_exit

    fn serbox_exit(status : Int) -> Unit

    FFI: exit(3), the only way a command reports its status.

    serbox_getpid

    fn serbox_getpid() -> Int

    FFI: this process's pid, for the daemon's pid file.

    serbox_home

    fn serbox_home() -> String

    serbox's state directory: $SERBOX_HOME, else ~/.serbox.

    serbox_version

    let serbox_version : String

    The version of this serbox build.

    Single source for serbox version, the --help banner and the npm launcher. Keep it in step with moon.mod and npmjs/package.json.

    serve_log_path

    fn serve_log_path() -> String

    serve_loop

    async fn serve_loop(bind : String, port : Int) -> Unit

    The daemon loop. Binds loopback by default: the client reaches it through an ssh tunnel, so there is no reason to expose the port to the network.

    serve_pid_path

    fn serve_pid_path(port : Int) -> String

    serve_token

    async fn serve_token(create : Bool) -> String

    The daemon's token. create=true generates and stores one on first use; the file is 0600 because the token is as powerful as an ssh key.

    serve_token_path

    fn serve_token_path() -> String

    set_json_mode

    fn set_json_mode(on : Bool) -> Unit

    shell_join

    fn shell_join(args : Array[String]) -> String

    Join arguments into one shell command line, quoting each.

    shell_quote

    fn shell_quote(arg : String) -> String

    Quote one argument for a POSIX shell, so exec can hand a shell string through bash -lc without the caller's metacharacters being reinterpreted a second time.

    skill_description

    fn skill_description(name : String) -> String

    The one-line description: from a skill's front matter.

    skill_targets

    fn skill_targets() -> Array[SkillTarget]

    The directories each agent reads skills from, relative to HOME. Codex, Cursor and OpenCode share ~/.agents/skills; installing there once avoids every agent showing the same skill twice.

    snapshot_config_path

    fn snapshot_config_path(name : String) -> String

    snapshot_image

    fn snapshot_image(snapshot : String) -> String

    The image a snapshot is stored as.

    snapshot_image_prefix

    let snapshot_image_prefix : String

    Prefix of every Docker image a snapshot creates.

    snapshots_dir

    fn snapshots_dir() -> String

    split_assignment

    fn split_assignment(text : String) -> (String, String)?

    KEY=VALUE split at the first =. None when there is no =.

    start_container

    async fn start_container(box : String) -> DockerResult

    Boot a stopped container; files stay, processes do not.

    start_job

    async fn start_job(config : BoxConfig, command : Array[String], cwd : String?, env : Map[String, String], timeout_secs : Int64?) -> Job

    Start a detached job: a script inside the box writes its own log and exit status, so nothing has to stay running on the host to watch it.

    stdout_is_tty

    fn stdout_is_tty() -> Bool

    Whether stdout is a terminal. Colors are for people; a pipe or a CI log gets plain text, and --json never gets either.

    stop_container

    async fn stop_container(box : String) -> DockerResult

    Shut a container down.

    template_image

    fn template_image(template : String) -> String?

    The image a template starts from. Everything here is a public Docker Hub image, so a fresh server needs no registry of its own.

    template_names

    let template_names : Array[String]

    touch_box

    async fn touch_box(config : BoxConfig) -> Unit

    Mark a box as used now. Every command that runs something in a box calls this, so the idle check measures work, not file timestamps.

    trim_trailing_slash

    fn trim_trailing_slash(path : String) -> String

    The last path segment, without a trailing slash.

    truncate_utf8

    fn truncate_utf8(text : String, limit : Int) -> String

    Truncate to at most limit bytes without splitting a UTF-8 character, so stored command output stays valid JSON.

    unpause_container

    async fn unpause_container(box : String) -> DockerResult

    Resume a paused container where it left off.

    unpublish_box_ports

    async fn unpublish_box_ports(box : String) -> Unit

    Stop every forwarder a box owns. rm and gc use this so a removed box cannot leave a listener behind; a box with no published ports is a no-op.

    unpublish_port

    async fn unpublish_port(box : String, container_port : Int) -> Unit

    Stop a published port.

    upsert_host

    async fn upsert_host(record : HostRecord) -> Unit

    Replace one host record, or append it when the name is new.

    usage_error

    fn usage_error(message : String) -> CliError

    user_home

    fn user_home() -> String

    The invoking user's home directory, without an FFI call: HOME covers every shell and service manager serbox is expected to run under.

    valid_box_name

    fn valid_box_name(name : String) -> Bool

    Box names double as Docker container suffixes and file names, so they are restricted to what is safe in both: lowercase letters, digits, _ and -, starting with a letter or digit, at most 40 characters.

    valid_env_key

    fn valid_env_key(key : String) -> Bool

    Environment variable names: a letter or _, then letters, digits or _.

    valid_secret_name

    fn valid_secret_name(name : String) -> Bool

    Secret names become environment variables, so they follow the same rules.

    valid_snapshot_name

    fn valid_snapshot_name(name : String) -> Bool

    Snapshot names end up in image tags, so they follow Docker's tag rules and stay clear of serbox's own sn/im prefixes.

    with_box_defaults

    Fill in fields a record written by another serbox build did not have, so a field added in a newer version never makes an older box unreadable.

    write_secret

    async fn write_secret(path : String, text : String) -> Unit

    Write a file only the owner can read, for hosts and secrets.

    write_text

    async fn write_text(path : String, text : String) -> Unit

    Replace a file's contents.

    yellow

    fn yellow(text : String) -> String