SPAWNBOX

Getting started

Get a Linux host, install Spawnbox, check KVM and create your first sandbox, step by step.

In these steps, you install Spawnbox on a Linux server. Then you create your first sandbox.

Two computers are used in these steps:

  • Your computer: your laptop or desktop. You use it to connect to the host.
  • The host: the Linux server that runs Spawnbox and the sandboxes.

Each step tells you on which computer to type the commands.

WARNING: Do not use your personal computer or a production server as the host. Sandboxes run code that you do not trust.

NOTE: You cannot run Spawnbox on macOS or Windows. You can use them only as “your computer” to connect to the host.

Step 1: Get a host

Get a Linux server that agrees with these requirements:

Item Requirement
CPU x86_64 (Intel or AMD). ARM is not supported.
Virtualization KVM (/dev/kvm) is recommended, but it is not necessary. With KVM, sandboxes are Firecracker microVMs. Use a bare-metal server, or a cloud VM with nested virtualization, for example AWS C8i, M8i or R8i, or Google Cloud N2. Without KVM, sandboxes are gVisor containers. See Firecracker or gVisor.
Operating system Ubuntu 22.04 or later, or Debian 12 or later
Memory Minimum 4 GiB. Each sandbox uses 1 GiB by default.
Disk Minimum 40 GiB free. An SSD or NVMe disk makes pause and resume faster.
Access A user account with sudo, and internet access

Step 2: Connect to the host

On your computer, type this command. Use the user name and the IP address of your host:

ssh ubuntu@203.0.113.10

[!NOTE] ubuntu and 203.0.113.10 are examples. Replace them with the user name and the public IP address of your host. Your cloud console shows these values. For AWS EC2, the user name for Ubuntu images is ubuntu.

Type all the commands in steps 3 to 7 on the host.

Step 3: Find out if KVM is available

  1. Type this command:

    ls -l /dev/kvm
  2. Make sure that the output shows a line like this:

    crw-rw---- 1 root kvm 10, 232 Nov  4 10:00 /dev/kvm
  3. If the output shows No such file or directory, KVM is not available. You can continue. Spawnbox then runs sandboxes in gVisor. For Firecracker microVMs, use a different host, or turn on nested virtualization for this host.

Step 4: Install Spawnbox

CAUTION: Run the installer as your usual user, not with sudo. The installer uses sudo when it must.

  1. Type this command:

    curl -fsSL https://spawnbox.tulipfarm.ai/install.sh | sh

    The command downloads the latest release, checks its SHA-256 sum and installs it. A release has the built programs, a Linux kernel for the sandboxes, a Debian disk image, Firecracker and gVisor (runsc). The installer also installs the system tools that Spawnbox uses, and starts the spawnbox systemd service. It takes about a minute.

    To upgrade later, type the same command again. To install a specific release, set SPAWNBOX_VERSION, for example curl -fsSL ... | SPAWNBOX_VERSION=v0.1.0 sh.

    You cannot go back to a release before the one that encrypts stored env. Its first start changes the database, and earlier releases then stop at start instead of losing the env. Back up <data-dir> (or the Postgres database) before you upgrade.

    To compile Spawnbox from the code instead, set SPAWNBOX_FROM_SOURCE=1. The command then downloads the code into ~/spawnbox, installs the build tools and Rust, and compiles everything. This takes about 30 minutes because it compiles a kernel. You can also clone the repository yourself and type deploy/install.sh.

  2. Wait until the installer stops. The last lines of the output must look like this:

    ==> Spawnbox is running at http://127.0.0.1:8080
    
    API key (shown once; ...):
    sbx_org_...
  3. Copy the API key and keep it in a safe location.

    CAUTION: Spawnbox shows the key only one time. If you lose it, make a new key with this command: sudo /opt/spawnbox/bin/spawn-api create-key --data-dir /var/lib/spawnbox

On a first install, the installer also starts builds of the coding agent templates. To skip them, set SPAWNBOX_AGENT_TEMPLATES=0, for example curl -fsSL https://spawnbox.tulipfarm.ai/install.sh | SPAWNBOX_AGENT_TEMPLATES=0 sh.

The installer puts files in these locations:

Location Contents
/opt/spawnbox Programs, kernel, base disk and template files
/etc/spawnbox/spawnbox.env Server settings
/var/lib/spawnbox Database, templates, paused sandboxes and secrets

Step 5: Make sure that Spawnbox operates

  1. Type this command:

    curl http://127.0.0.1:8080/healthz
  2. Make sure that the output is ok.

  3. If the output is not ok, go to Troubleshooting.

  4. To see the backend of the host, type this command:

    sudo journalctl -u spawnbox | grep "sandboxes run in"

    The output shows sandboxes run in firecracker or sandboxes run in gvisor.

Step 6: Create your first sandbox

  1. Keep the server address and your API key in two variables. Put your key in place of <your-key>:

    export B=http://127.0.0.1:8080/v1
    export A="Authorization: Bearer <your-key>"
  2. Create a sandbox and keep its ID in the variable S:

    S=$(curl -s -H "$A" -d '{"timeout_s": 600}' $B/sandboxes |
      python3 -c 'import json,sys; print(json.load(sys.stdin)["id"])')
    echo $S

    The output shows an ID, for example sbx_c7mty9fysaf0t3d5.

  3. Run a command in the sandbox:

    curl -s -H "$A" -d '{"cmd": "uname -a && whoami"}' $B/sandboxes/$S/exec

    The output is JSON. The stdout field shows the Linux version and the user name user.

  4. Delete the sandbox:

    curl -s -H "$A" -X DELETE $B/sandboxes/$S

Commands in a sandbox run as user in the directory /workspace. The user user can use sudo.

Step 7 (optional): Use Spawnbox from your computer

The API listens only on the host (127.0.0.1). To use it from your computer, make an SSH tunnel.

  1. On your computer, open a new terminal.

  2. Type this command and keep the terminal open:

    ssh -N -L 8080:127.0.0.1:8080 -L 8081:127.0.0.1:8081 ubuntu@203.0.113.10
  3. On your computer, in a different terminal, use http://127.0.0.1:8080 as the server address. Port 8081 gives you the preview URLs.

This page is the “Getting started” section of README.md ↗. Found a mistake? Edit it on GitHub ↗