boxfork on AWS
This guide tells you how to run boxfork on one EC2 instance in your own AWS account. The machine, its data and its bill are yours. Nothing goes through a different person or company.
We did not run these steps on a real AWS account. We wrote these steps from the documentation of AWS and from runs of the same installer on a local Ubuntu 24.04 system. Use the first run as a test, and tell us what is different.
Choose the instance
Section titled “Choose the instance”| For | Instance type | Machine image (AMI) |
|---|---|---|
| CPU sandboxes | any x86_64 or arm64 (Graviton) type, such as t3.large or t4g.large |
Ubuntu Server 24.04 LTS |
| GPU sandboxes | a type with NVIDIA GPUs, such as g4dn.xlarge (T4), g6.xlarge (L4) or g5.xlarge (A10G) |
Deep Learning Base OSS Nvidia Driver GPU AMI (Ubuntu 24.04) |
The GPU image is important, because the installer does not install the NVIDIA driver. AWS says that this image includes the driver, Docker and the NVIDIA Container Toolkit. The version of the driver changes with the build of the image, and gVisor supports a fixed list of versions. This guide cannot promise that the two agree. The installer does a check on the machine and gives a warning if gVisor does not know the driver.
A sandbox with a GPU gets a whole GPU. Thus an instance with four GPUs runs four GPU sandboxes at the same time.
Give the disk sufficient space for images. A good start is 100 GB. Use more if the sandboxes pull large images or models.
Keep the instance’s credentials away from sandboxes
Section titled “Keep the instance’s credentials away from sandboxes”Code in a sandbox must not get the permissions that the instance has in your account. There are three measures. Each measure is sufficient for the usual case:
- Attach no IAM role (instance profile). Attach a role only if something on the machine needs one. Without a role, the metadata service has no credentials to give.
- Require IMDSv2 with a hop limit of 1. In the console: Advanced details → Metadata version “V2 only”, Metadata response hop limit 1.
With the CLI:
--metadata-options "HttpTokens=required,HttpPutResponseHopLimit=1". A container is one hop farther away than the instance, so it cannot get the token that IMDSv2 asks for. - boxfork blocks the metadata address for sandboxes. It does this in the firewall of the machine when you install it as shown below.
boxfork infoshows if the block is active. See install.md.
Security group
Section titled “Security group”Permit SSH (port 22) from your own address, and permit nothing else. The API stays on the machine itself, and you reach it through an SSH tunnel. Thus it is not necessary to open a different port.
Way 1: copy and install
Section titled “Way 1: copy and install”This way works at this time, with a release that you built (make dist, see install.md).
-
Launch the instance with the image and the security group above.
-
Copy the installer and the archive for the chip type of the instance to the instance.
-
Run the installer on the instance. These commands do steps 2 and 3:
Terminal window scp dist/install.sh dist/boxfork-linux-amd64.tar.gz ubuntu@<address>:ssh ubuntu@<address> sudo sh install.sh --from ./boxfork-linux-amd64.tar.gzOn a Graviton instance, use
boxfork-linux-arm64.tar.gz.
Way 2: install at first boot
Section titled “Way 2: install at first boot”The instance installs boxfork by itself while it starts. For this, the release must be at an https address that the instance can read. An example is a folder in an S3 bucket of yours. The files contain nothing secret.
-
Build the release with the address that it will have. Then publish the release:
Terminal window make dist VERSION=0.1.0 RELEASE=https://<bucket>.s3.<region>.amazonaws.com/boxfork/0.1.0aws s3 cp dist/ s3://<bucket>/boxfork/0.1.0/ --recursiveThe instance must be able to read the folder without a sign-in. For this, you need a bucket policy that permits
s3:GetObjectonboxfork/*for everyone. S3 rejects such a policy while “Block public access” is on. This setting is in two places:- for the bucket (the two settings about bucket policies)
- for the whole account (S3 → Block Public Access settings for this account)
The two places must permit the policy, so use a bucket that contains nothing else. If you cannot change the setting of the account, use Way 1. As an alternative, serve the folder from an https address that you already have.
-
If you did not put
RELEASE=on themakeline, setRELEASEat the top ofdist/cloud-startup.shmanually.dist/cloud-startup.shnow contains that address and the checksums of the installer and the archives of this release. Thus the instance installs those files or nothing, and it is not important who can write to the bucket. -
Launch the instance, and paste the script into Advanced details → User data. The script runs one time, as root, at the first boot.
-
After some minutes, look at the result:
Terminal window ssh ubuntu@<address> sudo tail -40 /var/log/boxfork-install.logIf that file does not exist, the script did not start. In that case, look at
/var/log/cloud-init-output.log.
The first-boot script sets up the service only for the machine itself.
To change this later, run the installer that the script kept.
This is also the way to change to HTTPS.
Use sudo sh /etc/boxfork/install.sh --from /usr/local/bin/boxfork with the options from install.md.
Use it
Section titled “Use it”The boxfork command on your own computer is the same binary, built for your computer.
make build in the source tree puts the binary in bin/boxfork.
The commands below assume that the binary is on your PATH (export PATH="$PWD/bin:$PATH").
ssh ubuntu@<address> sudo cat /var/lib/boxfork/api-keyssh -N -L 7070:127.0.0.1:7070 ubuntu@<address> &export BOXFORK_URL=http://127.0.0.1:7070export BOXFORK_API_KEY=<the key>boxfork info # isolation should say gvisor; GPUs, how many it found; # "kept from the cloud metadata service" should say yesOn a GPU instance, make sure that a sandbox gets a GPU:
id=$(boxfork create --gpu 1)boxfork exec $id nvidia-smiboxfork kill $idOn a GPU instance, boxfork info must count the GPUs of the instance.
If it shows 0, read the warnings at the end of the install log.
The warnings tell you what is missing.
Serving it to other machines
Section titled “Serving it to other machines”Other instances in the same VPC can use the API over the private network:
- Install with
--listen <private address>:7070. - Add a security group rule that permits that port only from those instances.
For all use outside a private network, serve the API over HTTPS. HTTPS also needs port 80 open to the internet, for the issue and the renewal of the certificate. install.md describes the two ways.
The instance costs money while it runs, also when no sandbox uses it.
Stop the instance when you do not need it.
For a stopped instance, you pay only for its disk.
Sandboxes do not stay after a stop of the machine, but snapshots stay.
serve --gpu-idle-suspend releases a GPU from an idle sandbox for other sandboxes.
It does not decrease the bill.