Skip to content

Install boxfork on a Linux machine

This page tells you how to install boxfork on a Linux machine, and how to change, serve and remove it.

boxfork runs on one Linux machine (x86_64 or arm64) that has Docker. The installer installs all other parts:

  • gVisor
  • the NVIDIA Container Toolkit, on a GPU machine
  • the boxfork binary
  • a service that starts at boot

What we tried. We ran these items on a new Ubuntu 24.04 system (arm64) with Docker 29 and gVisor:

  • the installer
  • an upgrade
  • the first-boot script
  • HTTPS
  • the container image

Nothing on this page ran on a machine with an NVIDIA GPU, on x86_64 or on a real cloud account. On a system without apt (Fedora, RHEL and related systems), the steps of the installer ran only against stand-ins. We wrote the cloud guides (AWS, Google Cloud) from the documentation of the providers, and the guides say this.

There is no published release at this time, so you must build one. Run this command on a computer that has Go 1.26 or later:

Terminal window
make dist VERSION=0.1.0

Then dist/ contains all that a machine needs:

File What it is
boxfork-linux-amd64.tar.gz, boxfork-linux-arm64.tar.gz the daemon, for each chip type
install.sh the installer
cloud-startup.sh a script for a cloud’s “run at first boot” field, with this release’s checksums written into it
*.sha256 the checksum of the installer and of each archive

If you plan to serve the release from an address (for the first-boot script), give the address. Then the build also writes the address into that script: make dist VERSION=0.1.0 RELEASE=https://example.com/boxfork/0.1.0.

  1. Copy the installer and the archive for the chip type of the machine to the machine.

  2. Run the installer on the machine:

    Terminal window
    sudo sh install.sh --from ./boxfork-linux-amd64.tar.gz

The installer does these steps:

  1. If Docker is missing, it installs Docker with the script from Docker.
  2. On a machine with an NVIDIA GPU and driver, it installs the NVIDIA Container Toolkit and tells Docker about it.
  3. It installs gVisor and registers gVisor with Docker. It also does a check that gVisor supports the version of the GPU driver.
  4. It installs the binary and a systemd service.
  5. It starts a test sandbox, runs a command in the sandbox and removes the sandbox.

At the end, the installer prints what the daemon found: the isolation, the GPUs, and if snapshots work. It also prints each warning from the run. Run sh install.sh --help to see the options.

The installer does not install the NVIDIA driver itself. Start from a machine image that includes the driver.

When you run the installer again, it upgrades boxfork in place. The sandboxes continue to run, and the service keeps its settings.

If the service that the installer set up does not answer, the installer gives a warning and still ends with success. If a script must know about this condition, add --require-daemon. With this option, a service that does not answer is a failure.

The API listens only on the machine itself (127.0.0.1:7070). The API needs an API key. The daemon wrote the API key to /var/lib/boxfork/api-key.

To use the API from your own computer, open a tunnel. Then set the CLI or an SDK to use the tunnel:

Terminal window
ssh -N -L 7070:127.0.0.1:7070 <user>@<machine> &
export BOXFORK_URL=http://127.0.0.1:7070
export BOXFORK_API_KEY=<the key>
boxfork info

The safe default is the tunnel above. There are two other ways.

Make the daemon listen on the private address of the machine. Let the firewall of the cloud control who can reach the port.

Caution: Use this way only where you trust the network between the machines. This way is plain HTTP, and the API key goes through the network without encryption.

Terminal window
sudo sh install.sh --from ./boxfork-linux-amd64.tar.gz --listen 10.0.0.5:7070

Give the daemon a certificate and the key of the certificate. The commands below need these two things:

  • a domain name that points to the machine
  • certbot on the machine (sudo apt-get install certbot on Ubuntu)
Terminal window
sudo certbot certonly --standalone -d box.example.com \
--deploy-hook "systemctl restart boxfork || true"
sudo sh install.sh --from ./boxfork-linux-amd64.tar.gz --listen 0.0.0.0:443 \
--tls-cert /etc/letsencrypt/live/box.example.com/fullchain.pem \
--tls-key /etc/letsencrypt/live/box.example.com/privkey.pem
  • certbot --standalone answers the certificate authority on port 80. Thus port 80 must be open to the internet during the issue of the certificate and during each renewal. Port 443 must be open to each client of the API.
  • The installer does a check of the result. It sends a request to the daemon over HTTPS from the machine itself, and it trusts only the certificate that you gave. It starts a test sandbox in the same way.
  • HTTPS stays on when you run the installer again with other settings. Only --no-tls sets HTTPS to off.

The first-boot script keeps the installer that it used at /etc/boxfork/install.sh. On a machine that the first-boot script installed, use this command to set HTTPS to on: sudo sh /etc/boxfork/install.sh --from /usr/local/bin/boxfork --listen 0.0.0.0:443 --tls-cert ... --tls-key .... The first-boot script cannot do this, because a new machine does not have a certificate.

Then set BOXFORK_URL=https://box.example.com. The daemon reads the certificate when it starts, so the daemon must restart after a renewal. The hook in the command above does the restart. The first time, before the service exists, the hook does nothing. The sandboxes continue to run during a restart.

Caution: Also with HTTPS, open the port only to the addresses that need it. One API key gives full control of all sandboxes.

Put more flags for the daemon in --extra-args, for example:

Terminal window
sudo sh install.sh --from ./boxfork-linux-amd64.tar.gz \
--extra-args "--max-sandboxes 50 --gpu-idle-suspend 15m"

boxfork serve --help lists the flags. --extra-args replaces the extra flags that you gave before. The address, the isolation and HTTPS are separate settings, and the installer keeps them. To read the log of the service, use journalctl -u boxfork.

The settings are in /etc/boxfork/boxfork.env, and systemd reads this file. You can edit the file. After an edit, run systemctl restart boxfork. The installer uses the values that it finds in the file:

  • The installer keeps your own lines as they are, for example a proxy for the pull of images.
  • The installer reads its five settings in the same way as systemd. If a setting is in the file two times, the last line applies. The next installation writes each setting one time, with that value.
  • A value can be in quotation marks. The installer refuses a backslash, and it refuses a setting that continues on the next line. Put each setting on one line.

A cloud machine can ask a fixed address, 169.254.169.254, about itself. The answer includes the start-up script of the machine. If the machine has a role (AWS) or a service account (Google Cloud), the answer also includes credentials for it. The traffic of a sandbox goes out through the machine, so code in a sandbox can also ask.

The service that the installer sets up prevents this. The daemon adds a rule to the firewall of the machine. The rule is a chain with the name BOXFORK-METADATA, and the DOCKER-USER chain of Docker goes to it. The rule refuses the traffic of sandboxes to that address and to the addresses near it. The daemon sets the rule again each half minute, in case something removed it.

Name lookups (port 53) stay permitted, because on some clouds the name server is at the same address. boxfork info shows the result:

sandboxes kept from the cloud metadata service yes
  • The installer gives a warning when the answer is no, and the log of the daemon gives the cause. These are the usual causes:
    • The daemon does not run as root.
    • The configuration of Docker uses nftables and not iptables.
    • The daemon runs as a container.
  • With --extra-args "--block-metadata require", the daemon does not start where it cannot set the rule. With this setting, the daemon also sets the rule again before each sandbox that goes on the network. The daemon refuses the sandbox where it cannot set the rule. The cost is a small number of firewall commands for each sandbox. Without this setting, the daemon repairs a firewall that something reset in less than half a minute. Sandboxes that a client creates in that interval can reach the service.
  • --extra-args "--block-metadata off" removes the rule. It also removes the rule that an earlier run of the daemon set.
  • The daemon keeps the rule first in the DOCKER-USER chain of Docker. If a rule of yours must come before it, the daemon moves your rule behind it at the next half minute. To let sandboxes reach these addresses, use off.
  • The rule is one layer of protection. Do not give the machine a role or a service account that it does not need. The AWS and Google Cloud guides show how to do this.

Under gVisor, a sandbox cannot reach the name server that Docker runs for its networks. Thus the daemon makes each new sandbox ask the name servers to which Docker itself forwards. If the log of the daemon says that names will not resolve, Docker gave no name server that the daemon can use. An example is a machine whose only name server is on 127.0.0.x. In that case, give the name servers yourself with --extra-args "--dns 10.0.0.2 --dns 1.1.1.1".

To give each sandbox one shared, read-only directory, for example for model weights, add --volume:

Terminal window
sudo sh install.sh --from ./boxfork-linux-amd64.tar.gz \
--extra-args "--volume models:/models:ro"

The daemon creates the volume on the first start and keeps it during upgrades. The section about volumes in the README shows how to fill the volume. The volume is in the storage of Docker, so the disk of that storage needs the space. docker volume inspect boxfork-vol-models shows the location.

For machines on which all software runs in containers, the daemon is also a container image. The daemon controls the Docker of the machine through the socket of Docker. Because gVisor is a part of the machine and not of the image, set up gVisor first. --engine-only does this and does not install the daemon or a service:

Terminal window
sudo sh install.sh --engine-only
sudo docker build -t boxfork . # in the source tree
sudo docker run -d --name boxfork --restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/lib/boxfork:/var/lib/boxfork \
-p 127.0.0.1:7070:7070 boxfork
sudo cat /var/lib/boxfork/api-key

There is no published image at this time. Thus docker build needs the source of this repository on the machine. As an alternative, build the image on a different computer and move it with docker save boxfork | ssh <machine> sudo docker load.

  • A program that can reach the Docker socket controls the machine. Thus this container has the same trust as root on the machine.

  • If the machine does not have gVisor, the daemon tells you that the sandboxes are plain containers.

  • From a container, the daemon cannot set the firewall of the machine. Thus sandboxes can reach the metadata service of the cloud, and boxfork info shows this. On a cloud machine, add the rule yourself after the daemon starts, and give the machine no role or service account. The rule stays until the machine restarts.

    Terminal window
    subnet=$(docker network inspect boxfork --format '{{(index .IPAM.Config 0).Subnet}}')
    for dst in 169.254.0.0/16 168.63.129.16 100.100.100.200 192.0.0.192; do
    sudo iptables -I DOCKER-USER -s "$subnet" -d "$dst" -p tcp ! --dport 53 -j REJECT
    sudo iptables -I DOCKER-USER -s "$subnet" -d "$dst" -p udp ! --dport 53 -j REJECT
    done

    These are the addresses to which the rule of the daemon applies, for TCP and UDP. The rule of the daemon also refuses all other kinds of traffic to these addresses. If something makes the boxfork network again, the network can get a different range. Then you must set the rule again for the new range.

  • The image has no NVIDIA tools and gives no GPUs. On a GPU machine, use the installer.

  • The log of the daemon gives a warning that the API is on plain HTTP outside the machine. The cause is that the daemon sees the address of the container, not the -p 127.0.0.1: in front of it.

  • Caution: Run only one daemon for each Docker. A second daemon removes the sandboxes of the first daemon when it starts.

Terminal window
sudo sh install.sh --uninstall

This command removes the service and the binary. It keeps these items:

  • the sandboxes that run
  • the data in /var/lib/boxfork
  • the settings
  • Docker
  • gVisor

A machine that the first-boot script installed stays without boxfork at later boots.

  • No other person has an account on the machine. A person who can use Docker on the machine has the same power as root and can read the API key. With plain HTTP, there is one more risk. A local user can take the port of the API while the daemon does not run. Then the next boxfork command that runs on the machine sends the API key to that user. With HTTPS, that command examines the certificate first.

  • A machine image that you make from the machine is a copy of the machine. The copy includes the API key. Each machine that starts from the image answers to the same API key. Before you make an image, do these steps:

    1. Stop the service.
    2. Delete /var/lib/boxfork/api-key.

    Then each new machine writes its own API key when the service starts for the first time.

A service that rents a container, and not a machine, cannot run boxfork. Docker and gVisor do not run in such a container. For boxfork, you need a virtual machine or a physical machine.

The installer also needs Docker as the systemd service docker.service. The packages from Docker set up this service. If Docker comes from a snap package, or a different engine answers to the docker command, the installer tells you and changes nothing. In that case, install Docker Engine from docker.com first.