Skip to main content

Example: GitHub Actions

You use this pattern when GitHub Actions is your orchestrator and you want heavy or isolated work (builds, tests, image tooling) to run inside a VoidRun sandbox instead of on the default ubuntu-latest runner alone. You inject VR_API_KEY from secrets, you name sandboxes so you can correlate logs with GITHUB_RUN_ID, you exec with a long timeout and optional streaming, and you remove the sandbox in a finally block. A full production-style script lives in this repository at image-builder/.github/scripts/build-in-sandbox.ts: it creates a docker image sandbox, clones the repo with GITHUB_TOKEN, runs a multi-step shell build, and streams stdout/stderr. This page distills that pattern so you can adapt it without copying image-builder specifics.

What you accomplish

You trigger a workflow on push, pull_request, or workflow_dispatch. A step runs Node (or Python) on the runner, calls @voidrun/sdk or voidrun, provisions a sandbox, runs your commands, then deletes the sandbox even when the job fails.

Prerequisites

You completed Examples overview. You add a repository secret:
Older internal scripts sometimes used VOIDRUN_API_KEY. You should standardize on VR_API_KEY for new workflows so you match the SDKs & API docs.Self-hosted: set VR_API_URL (or pass baseUrl / base_url) in the workflow env and in your script: see Self-hosted deployments.
You grant GITHUB_TOKEN (default) contents: read (or broader if you clone private submodules) so the sandbox can git clone your repository.

Pattern from build-in-sandbox.ts

The reference script does the following (you mirror the same shape in your own repo):
  1. Read GITHUB_REPOSITORY, GITHUB_SHA, GITHUB_RUN_NUMBER, GITHUB_TOKEN, GITHUB_SERVER_URL.
  2. Construct a clone URL with x-access-token when a token is present (HTTPS clone inside the sandbox).
  3. createSandbox with a unique name, enough CPU/memory, autoSleep: false for long jobs, and image: 'docker' when the workload needs Docker in the VM (see System images).
  4. Upload a generated shell script with fs.uploadFile, chmod, then exec with timeout (e.g. 3600 seconds) and onStdout / onStderr / onExit handlers.
  5. remove the sandbox in finally.
You do not commit the API key; you pass it only via env from secrets.

Step 1: Workflow job skeleton

You check out the repo on the runner, you install Node, you run your script.

Step 2: TypeScript runner (trimmed pattern)

You keep the script small on the runner; you put the heavy logic in the shell you upload or in exec commands. This example clones the default branch at GITHUB_SHA and runs ./scripts/ci.sh (you replace that with your commands).
If ./scripts/ci.sh does not exist in your repo yet, replace that line with echo ok until you wire real steps. For Docker-in-Docker or qemu-style builds, switch image to docker and raise mem like the reference (~14 GB in build-in-sandbox.ts).

Step 3: Python variant (sync)

You can run the same flow with voidrun on the runner if you prefer Python.

Practices you should follow

  • You use permissions: minimally (contents: read for clone-only jobs).
  • You never print VR_API_KEY or embed it in the shell script string: only GITHUB_TOKEN appears in the generated clone URL inside the sandbox, which is still sensitive; rotate tokens per job policy.
  • You set autoSleep: false when the job can run longer than the idle-sleep window.
  • You cap concurrency (concurrency: group) if each run creates a large docker sandbox.
  • You read CI test runner for simpler exit-code-only jobs without streaming.

Reference in this repository

The image-builder workflow script (image-builder/.github/scripts/build-in-sandbox.ts) demonstrates:
  • docker image, 14 GB RAM, autoSleep: false
  • Streaming exec with onStdout / onStderr / onExit
  • Uploading a large inline build.sh and running it with sudo
  • finally cleanup with error logging on remove

CI test runner

Simpler exec + exit code pattern

Code execution

Streaming and timeouts