Skip to content

Run boxfork on a few Linux machines with k3s

This guide is for a team that has a few Linux machines and no Kubernetes, and wants sandboxes on all of them. It makes a small Kubernetes cluster from three plain machines with k3s, and installs boxfork on it. At the end, your agents create, fork and kill sandboxes on the three machines from the Python SDK, as on one machine. When you drain a machine, its sandboxes move to a different machine with their files and their IDs. It takes about one hour, most of it for the commands on each of the three machines.

For one machine, install.md is simpler. For a cluster that you have, read install.md. Decision 17 gives the reason for Kubernetes.

The guide uses CPU sandboxes only, because the API service on Kubernetes refuses a sandbox with a GPU at this time. For GPUs, use one machine: see gcp.md. On 6 December 2026, a script did all steps of this guide on three new machines: What ran on real machines gives the record.

You need three machines:

Item Value
System Ubuntu 24.04, x86_64 or arm64. Other distributions of Linux with systemd can work, but we did not try them.
Size 4 CPUs, 16 GB of memory and 50 GB of disk for each machine
Network One private network for the three machines, and access to the internet
Access SSH from your computer to each machine, with sudo

The guide calls one machine the server and the two other machines the agents, and all three run sandboxes.

The machines must reach each other at these ports. The k3s documentation gives the full list.

Port From To Use
6443/tcp The agents The server The Kubernetes API server
8472/udp Each machine Each machine The pod network of k3s (flannel VXLAN)
10250/tcp Each machine Each machine The kubelet

Caution: Do not open these ports, or the port 30500, to the internet. Port 30500 is the registry of the snapshots on each node.

Your computer needs:

  • a checkout of boxfork
  • kubectl and Helm
  • Docker or Podman, to build the images
  • Python 3.9 or later, for the SDK

Step 3 builds the images on your computer, as the recorded run did. Since version 0.1.0, each release also publishes the images on GHCR, and the chart uses them by default. This guide was not run with the published images.

In the commands, replace these names with your values:

Name Value
SERVER The SSH address of the server, for example ubuntu@203.0.113.10
AGENT1, AGENT2 The SSH addresses of the agents
SERVER_IP The private IP address of the server, for example 10.128.0.5
NODE_CIDR The address range of the private network of the machines, for example 10.128.0.0/20
  1. On the server, install k3s:

    Terminal window
    curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.37.3+k3s1 sh -
  2. On the server, show the join token. Keep it secret, because with it a machine can join the cluster.

    Terminal window
    sudo cat /var/lib/rancher/k3s/server/node-token
  3. On each agent, put the token in a file that only root can read:

    Terminal window
    sudo mkdir -p /etc/rancher/k3s
    sudo sh -c 'umask 077; cat > /etc/rancher/k3s/token'

    Paste the token, push Enter, then push Ctrl-D.

  4. On each agent, install k3s as an agent of the server:

    Terminal window
    curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.37.3+k3s1 \
    K3S_URL=https://SERVER_IP:6443 K3S_TOKEN_FILE=/etc/rancher/k3s/token sh -
  5. On your computer, get the kubeconfig of the server:

    Terminal window
    ssh SERVER sudo cat /etc/rancher/k3s/k3s.yaml > ~/.kube/k3s-boxfork
    chmod 600 ~/.kube/k3s-boxfork
    export KUBECONFIG=~/.kube/k3s-boxfork
  6. In a different terminal, open an SSH tunnel to the API server. The kubeconfig gives the address https://127.0.0.1:6443.

    Terminal window
    ssh -N -L 6443:127.0.0.1:6443 SERVER
  7. Make sure that the three nodes are Ready:

    Terminal window
    kubectl get nodes -o wide

The column CONTAINER-RUNTIME gives the version of containerd. k3s 1.37 has containerd 2.

Each sandbox is a pod that runs under gVisor, so each node needs the programs of gVisor and two runtimes in containerd: runsc and runsc-offline. k3s writes the configuration of its containerd itself, from a template, so you add the runtimes to the template, not to config.toml.

Do steps 1 to 5 on each of the three machines.

  1. Download a release of gVisor, and make sure that it is correct:

    Terminal window
    cd "$(mktemp -d)"
    url=https://storage.googleapis.com/gvisor/releases/release/20261130.0/$(uname -m)
    curl -fsSL -O $url/gvisor.tar.bz2 -O $url/gvisor.tar.bz2.sha512
    sha512sum -c gvisor.tar.bz2.sha512
  2. Install the programs:

    Terminal window
    tar -xjf gvisor.tar.bz2
    sudo install -m 755 runsc containerd-shim-runsc-v1 /usr/local/bin/
    sudo mkdir -p /usr/local/bin/gvisor-bin
    sudo cp -r gvisor-bin/. /usr/local/bin/gvisor-bin/
    sudo chmod -R a+rx /usr/local/bin/gvisor-bin
  3. Write the settings of the two runtimes. overlay2 = "none" puts the files of a sandbox on the disk, where a snapshot finds them.

    Terminal window
    sudo mkdir -p /etc/containerd
    printf '[runsc_config]\n overlay2 = "none"\n' | sudo tee /etc/containerd/runsc.toml
    printf '[runsc_config]\n overlay2 = "none"\n network = "none"\n' | sudo tee /etc/containerd/runsc-offline.toml
  4. Write the template of containerd, /var/lib/rancher/k3s/agent/etc/containerd/config-v3.toml.tmpl. The first line keeps the configuration that k3s makes:

    {{ template "base" . }}
    [plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes.runsc]
    runtime_type = "io.containerd.runsc.v1"
    [plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes.runsc.options]
    TypeUrl = "io.containerd.runsc.v1.options"
    ConfigPath = "/etc/containerd/runsc.toml"
    [plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes.runsc-offline]
    runtime_type = "io.containerd.runsc.v1"
    [plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes.runsc-offline.options]
    TypeUrl = "io.containerd.runsc.v1.options"
    ConfigPath = "/etc/containerd/runsc-offline.toml"

    The name config-v3.toml.tmpl is for containerd 2. A k3s with containerd 1.7 reads config.toml.tmpl, with the section names of the version 2 of the configuration.

  5. Restart k3s. The service is k3s on the server and k3s-agent on an agent:

    Terminal window
    sudo systemctl restart k3s # on the server
    sudo systemctl restart k3s-agent # on an agent

    Then /var/lib/rancher/k3s/agent/etc/containerd/config.toml contains the two runtimes.

Then, on your computer:

  1. Make the two RuntimeClasses:

    Terminal window
    kubectl apply -f - <<'EOF'
    apiVersion: node.k8s.io/v1
    kind: RuntimeClass
    metadata:
    name: gvisor
    handler: runsc
    ---
    apiVersion: node.k8s.io/v1
    kind: RuntimeClass
    metadata:
    name: gvisor-offline
    handler: runsc-offline
    EOF
  2. Start a pod under gVisor, and read its kernel:

    Terminal window
    kubectl run gvisor-check --image=busybox:1.37 --restart=Never \
    --overrides='{"spec":{"runtimeClassName":"gvisor"}}' -- sleep 300
    kubectl wait --for=condition=Ready pod/gvisor-check --timeout=3m
    kubectl exec gvisor-check -- uname -r
    kubectl delete pod gvisor-check

    The kernel must end in -gvisor, for example 4.19.0-gvisor.

The chart needs two images, boxfork-operator and boxfork-helper. You build them for the chip type of the nodes and import them into the containerd of k3s on each node. You can also push them to a registry that the nodes can use, and give their names to the chart in step 4.

  1. In the checkout of boxfork, build the two images and save them to one file. For arm64 nodes, give linux/arm64.

    Terminal window
    docker build --platform linux/amd64 -f operator/Dockerfile -t localhost/boxfork-operator:k3s .
    docker build --platform linux/amd64 -f operator/helper.Dockerfile -t localhost/boxfork-helper:k3s .
    docker save -o boxfork-images.tar localhost/boxfork-operator:k3s localhost/boxfork-helper:k3s

    With Podman, use podman in place of docker.

  2. Copy the file to each machine, and import it there:

    Terminal window
    scp boxfork-images.tar SERVER:/tmp/
    ssh SERVER sudo k3s ctr -n k8s.io images import /tmp/boxfork-images.tar

    Do this step for AGENT1 and AGENT2 too.

  3. On each machine, make sure that containerd has the two images:

    Terminal window
    sudo k3s crictl images | grep boxfork

k3s has a network policy controller, so the network policies of boxfork keep the sandboxes apart with no more work. It also has a default storage class, local-path, which keeps each volume on the disk of one node. The API service and the registry of the snapshots each have a volume, so they stay on the node of their volume. Put them on the server, because the agents are the machines that you drain.

  1. Cordon the two agents, so that the parts of boxfork start on the server. Use the names of the nodes from kubectl get nodes:

    Terminal window
    kubectl cordon <agent1> <agent2>
  2. Make the namespace, and let it admit only pods of the Pod Security level baseline:

    Terminal window
    kubectl create namespace boxfork
    kubectl label namespace boxfork pod-security.kubernetes.io/enforce=baseline
  3. Find the address of the flannel tunnel of each node. It is the first address of the pod range of the node:

    Terminal window
    kubectl get nodes -o jsonpath='{range .items[*]}{.spec.podCIDR}{"\n"}{end}'

    For the range 10.42.1.0/24, the address is 10.42.1.0/32. Use the ranges of your nodes: a node that joins again gets a new range. You need these addresses because a node pulls the snapshots from the registry through its node port. If the registry is on a different node, the traffic comes from this address.

  4. Install the chart. Give the address ranges of k3s, the tunnel addresses, and the socket of the containerd of k3s:

    Terminal window
    helm install bf operator/chart -n boxfork \
    --set image.repository=localhost/boxfork-operator --set image.tag=k3s \
    --set helperImage.repository=localhost/boxfork-helper --set helperImage.tag=k3s \
    --set 'networkPolicy.podCIDRs={10.42.0.0/16}' \
    --set 'networkPolicy.serviceCIDRs={10.43.0.0/16}' \
    --set 'networkPolicy.nodeCIDRs={NODE_CIDR,10.42.0.0/32,10.42.1.0/32,10.42.2.0/32}' \
    --set snapshots.agent.containerdSocket=/run/k3s/containerd/containerd.sock \
    --wait --timeout 10m

    In nodeCIDRs, put NODE_CIDR and the tunnel addresses from item 3. 10.42.0.0/16 and 10.43.0.0/16 are the default ranges of the pods and the services of k3s. If you gave --cluster-cidr or --service-cidr to k3s, give those ranges. When a node joins later, add its tunnel address with helm upgrade --reuse-values. Without the tunnel addresses, the registry refuses the other nodes. A fork or a move to a different node then fails with ErrImagePull.

  5. Uncordon the agents:

    Terminal window
    kubectl uncordon <agent1> <agent2>
  6. Make sure that the API service saw the network keep the sandboxes apart:

    Terminal window
    kubectl -n boxfork logs deploy/bf-api | grep 'is serving'

    The line must give "network_isolated":true and "snapshots":true. If network_isolated is false, read “If the network plugin ignores network policies” in install.md.

  1. Make the API service available on your computer, in a different terminal:

    Terminal window
    kubectl -n boxfork port-forward svc/bf-api 7070:7070
  2. Install the SDK from the checkout, and give the address and the key to it:

    Terminal window
    pip install ./sdk/python
    export BOXFORK_URL=http://127.0.0.1:7070
    export BOXFORK_API_KEY=$(kubectl -n boxfork get secret bf-api-key -o jsonpath='{.data.api-key}' | base64 -d)
  3. Create a sandbox, write a file in it, and fork it into 3 copies:

    from boxfork import Sandbox
    sbx = Sandbox.create("ubuntu:24.04", timeout=1800)
    print("sandbox", sbx.id, sbx.run("uname -r").stdout.strip())
    sbx.files.write("/work/hello.txt", "hello from k3s\n")
    print("read", sbx.files.read("/work/hello.txt").strip())
    for copy in sbx.fork(3, timeout=1800):
    print("copy", copy.id, copy.files.read("/work/hello.txt").strip())

    timeout=1800 keeps each sandbox for 30 minutes. The default of the chart is 5 minutes.

  4. Find the node of each sandbox:

    Terminal window
    kubectl -n boxfork get sandboxes -o wide

    The scheduler puts the copies of one sandbox on different nodes when it can.

A drain of a node moves each sandbox on it to a different node, and the files and the ID of the sandbox stay. Its processes stop, because a move keeps only the files, as a snapshot does. install.md gives the details, and decision 20 gives the design.

Caution: Do not drain the server. The API service and the registry cannot move from it, because their volumes are on its disk.

  1. Select an agent that has sandboxes in the column NODE of kubectl -n boxfork get sandboxes -o wide.

  2. Drain it:

    Terminal window
    kubectl drain <agent> --ignore-daemonsets --delete-emptydir-data --timeout=10m
  3. Make sure that each sandbox runs on a different node now:

    Terminal window
    kubectl -n boxfork get sandboxes -o wide
  4. Read the file of a sandbox that moved, with its ID:

    from boxfork import Sandbox
    print(Sandbox.connect("<id>").files.read("/work/hello.txt"))
  5. When the work on the node is done, uncordon it:

    Terminal window
    kubectl uncordon <agent>
  6. Kill the sandboxes:

    from boxfork import Sandbox
    for sbx in Sandbox.list():
    sbx.kill()

Caution: Kill all sandboxes before you uninstall the chart, as in step 6. Without the operator, a Sandbox object stays, and the namespace does not go.

  1. Delete the snapshots, then uninstall the chart. The snapshots go first, because the node agents must delete their images. The uninstall also removes the namespace boxfork-bf-system, which the chart made.

    Terminal window
    kubectl -n boxfork delete sandboxsnapshots --all
    helm uninstall bf -n boxfork --wait
    kubectl delete namespace boxfork
    kubectl delete crd sandboxes.boxfork.dev sandboxsnapshots.boxfork.dev
    kubectl delete runtimeclass gvisor gvisor-offline
  2. On each agent, remove k3s:

    Terminal window
    sudo /usr/local/bin/k3s-agent-uninstall.sh
  3. On the server, remove k3s:

    Terminal window
    sudo /usr/local/bin/k3s-uninstall.sh
  4. On each machine, remove gVisor:

    Terminal window
    sudo rm -rf /usr/local/bin/runsc /usr/local/bin/containerd-shim-runsc-v1 /usr/local/bin/gvisor-bin
    sudo rm -f /etc/containerd/runsc.toml /etc/containerd/runsc-offline.toml

The uninstall scripts of k3s remove /var/lib/rancher/k3s, with the template of containerd, and /etc/rancher/k3s, with the token.

On 6 December 2026, scripts/proof/k3s-guide.sh did all steps of this guide on three new machines, from the start to the end. The script runs the commands of each step through SSH from a Mac, and checks the result. It runs the first Python block of this page as it is. 46 checks passed, and 0 failed.

Item Value
Machines 3 Google Cloud VMs, e2-standard-4 (4 CPUs, 16 GB), in us-central1-a, on the default network
System Ubuntu 24.04.5, kernel 7.0.0-1021-gcp, x86_64
k3s v1.37.3+k3s1, with containerd 2.3.7-k3s1, flannel VXLAN and kube-router
gVisor release-20261130.0
Your computer A Mac with arm64, Podman, Helm 4.3.2, kubectl 1.37.3
Step Time
1. k3s on the server and two agents, until the 3 nodes are Ready 59 s
2. gVisor on 3 nodes, with the check pods 93 s
3. The images to the 3 nodes, 57 MB. The first build of the images for amd64 on the Mac took 5 minutes, because Podman emulates amd64. 91 s
4. The chart, until the API service is ready 52 s
6. kubectl drain of an agent with 2 sandboxes 18 s
7. The removal of the chart and of k3s from 3 nodes 59 s

These checks passed:

Check Result
A pod with gvisor on each node 4.19.0-gvisor, and dmesg says “Starting gVisor”
A pod with gvisor-offline Only the network device lo
The API service isolation gvisor, network_isolated true, metadata_blocked true, snapshots true
Each node pulls from the registry at localhost:30500 It gets HTTP 401 without the login
A sandbox and the internet It connects to 1.1.1.1:443, and it finds kubernetes.default
A sandbox and the cluster It cannot connect to a different sandbox, the metadata service, the API service, the Kubernetes API server or a kubelet. A pod that is not a sandbox connects to each of them.
The Python block of step 5 It ran in 12 s. The 3 copies have the file, and they are on 3 different nodes.
The drain Each of the 2 sandboxes moved to a different node in 10 s. Each kept its ID, its Sandbox object, its file and a 20 MB file with the same SHA-256.
The removal No namespace and no CRD of boxfork. No k3s, no gVisor and no process of k3s or containerd on the 3 nodes.

The first runs found two problems. We corrected them before the run above:

  • kube-router rejects the traffic that a network policy blocks. A sandbox then gets “connection refused”, not a timeout. The check of the API service took this as a sandbox that reached another sandbox, and reported network_isolated as false. The check now uses a port that takes connections. See internals/kubernetes.md.
  • flannel sends the traffic of a node to the registry on a different node from its tunnel address. The policy of the registry refused it, and forks to other nodes failed with ErrImagePull. Step 4 now gives the tunnel addresses in networkPolicy.nodeCIDRs.
  • The API service and the registry stay on one node, because local-path keeps a volume on one node. If that node stops, the cluster has no API service and no snapshots until it starts again.
  • A sandbox with a volume cannot move to a different node: local-path keeps the volume on its node. Thus a drain waits for such a sandbox.
  • No GPUs. The API service on Kubernetes refuses a sandbox with a GPU.
  • The probe of the operator counts only a timeout as the policy. On k3s, it got a timeout from each sandbox pod. A plain pod got “connection refused” from the same pods.
  • We do not know why the operator got a timeout. We think that the policy of the operator pod drops the ICMP error of kube-router, but we did not prove it. If a different setup of k3s gives the operator “connection refused”, network_isolated stays false. See internals/kubernetes.md.

Not proven:

  • the guide by a person other than its author
  • a server with more than one machine (k3s with an embedded etcd)
  • network plugins other than flannel with kube-router, and machines that are not on Google Cloud
  • arm64 nodes, other distributions of Linux, and other versions of k3s
  • a node that joins after the install, and a drain of the server
  • large sandboxes, volumes, pools and many sandboxes at the same time