Start from a Docker image
Pass image to start from a Docker image instead of Groundbox's own: anything that docker pull takes, such as python:3.12-slim or ghcr.io/org/app:tag, an image in your Groundbox registry, or a private image on another registry with its login. You do not make a template first.
curl https://api.groundbox.dev/v1/sandboxes \
-H "Authorization: Bearer $GROUNDBOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"image": "python:3.12-slim"}'let sandbox = await groundbox.create_sandbox({ image: "python:3.12-slim" });
// The first sandbox from an image waits while the image is turned into a disk.
sandbox = await groundbox.wait_for_sandbox(sandbox.id);
if (sandbox.status === "failed") throw new Error(sandbox.error ?? "the sandbox failed");
const result = await groundbox.run_command(sandbox.id, "python -V");The first sandbox from an image comes back with status queued while the image is turned into a disk. That can take a few minutes for a large image. The sandbox moves to running when it is done. Its image field has the reference, the digest it resolved to and a status: queued, building, ready or failed. After that, a sandbox from the same image starts as fast as one from a template.
A tag is looked up again each time, at most a minute late. When it points at a new digest, the image is turned into a disk again. Name a digest (python@sha256:...) to pin one.
- The image's
ENVvariables are set for every command. A sandbox's ownenvwins. - Commands run as root. The image's
USERis not used. - Commands start in the home folder (
/root, or the image'sHOME), not in the image'sWORKDIR. Passcwdto run somewhere else. - The image's
ENTRYPOINTandCMDare not run. Start your program with a command. - The image does not need Node.js. Groundbox adds its own tools under
/opt/groundbox, so exec, streams, resumable and background commands, the command list and files all work on images likealpineandpython:3.12-slim. - A terminal (
tty: true) needs thescriptprogram from util-linux. Debian and Ubuntu images have it. On Alpine, installutil-linux-misc. - The image must be built for linux/amd64, and has to fit the sandbox's disk. Ask for a larger
disk_gbfor a large image. - A private image on another registry needs
image_auth; see below. An image in your Groundbox registry needs no login. - A team turns 2 new images into disks at a time, template builds included. A create past that is refused with
429: try again when one is done. imagecannot be combined withtemplate, and a schedule cannot use it. To add packages or files on top of an image, make a template from it.
A sandbox whose image cannot be used ends with status failed, and its error field says why: the image does not exist or is private, it is too large for the disk, or the build failed or ran past 30 minutes. An image that is not found is refused straight away with 404. The build's log is the log of the template named in the sandbox's template field; see templates made from images.
Private images on other registries
For a private image on GitHub's registry (ghcr.io), Docker Hub, Amazon ECR, Google Artifact Registry or any registry that speaks the Docker registry API, keep the password or token as a team secret and pass image_auth: the username and the secret's name. The key needs the secrets:use scope. Templates take the same field for a private base image.
# Once: keep the registry token as a team secret (a key with secrets:write).
curl -X PUT https://api.groundbox.dev/v1/secrets/GHCR_TOKEN \
-H "Authorization: Bearer $GROUNDBOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"value": "ghp_..."}'
# Then name it (a key with sandboxes:write and secrets:use).
curl https://api.groundbox.dev/v1/sandboxes \
-H "Authorization: Bearer $GROUNDBOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"image": "ghcr.io/acme/app:1", "image_auth": {"username": "bot", "password_secret": "GHCR_TOKEN"}}'printf %s "$GHCR_TOKEN" | groundbox secrets set GHCR_TOKEN
groundbox sandbox create --image ghcr.io/acme/app:1 --image-auth bot:GHCR_TOKEN
groundbox templates create app --image ghcr.io/acme/app:1 --image-auth bot:GHCR_TOKEN --pip requestsconst sandbox = await groundbox.create_sandbox({
image: "ghcr.io/acme/app:1",
image_auth: { username: "bot", password_secret: "GHCR_TOKEN" },
});sandbox = gb.create_sandbox(
image="ghcr.io/acme/app:1",
image_auth={"username": "bot", "password_secret": "GHCR_TOKEN"},
)- The username is what
docker login -utakes. GitHub: any name, with a token that hasread:packages. Docker Hub: your user name, with an access token. ECR:AWS, with the output ofaws ecr get-login-password. Artifact Registry:oauth2accesstoken, withgcloud auth print-access-token, or_json_keywith a service account key. - ECR and Artifact Registry access tokens expire (12 hours and 1 hour). Groundbox does not refresh them: set the secret again before it runs out, from a scheduled job of your own, or use a key that does not expire. A sandbox from an image already turned into a disk needs no login, so only a new image or a new tag needs a fresh token.
- The login is checked before anything is made. A refused one answers
400withdetails.reasonregistry_auth_failed; an image the registry does not have answers404, as without a login. - The password is opened only to ask the registry for the image's digest and, in the memory of the machine that pulls the image, for the pull. It is never in a response, a log, the sandbox or the template, and it is not on the image's disk. The disk made from a private image is your team's alone: another team naming the same image goes to the registry with its own login.