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 defaultubuntu-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 onpush, 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.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):
- Read
GITHUB_REPOSITORY,GITHUB_SHA,GITHUB_RUN_NUMBER,GITHUB_TOKEN,GITHUB_SERVER_URL. - Construct a clone URL with
x-access-tokenwhen a token is present (HTTPS clone inside the sandbox). createSandboxwith a uniquename, enough CPU/memory,autoSleep: falsefor long jobs, andimage: 'docker'when the workload needs Docker in the VM (see System images).- Upload a generated shell script with
fs.uploadFile,chmod, thenexecwithtimeout(e.g. 3600 seconds) andonStdout/onStderr/onExithandlers. removethe sandbox infinally.
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 inexec 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 withvoidrun on the runner if you prefer Python.
Practices you should follow
- You use
permissions:minimally (contents: readfor clone-only jobs). - You never print
VR_API_KEYor embed it in the shell script string: onlyGITHUB_TOKENappears in the generated clone URL inside the sandbox, which is still sensitive; rotate tokens per job policy. - You set
autoSleep: falsewhen the job can run longer than the idle-sleep window. - You cap concurrency (
concurrency:group) if each run creates a largedockersandbox. - 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:
dockerimage, 14 GB RAM,autoSleep: false- Streaming
execwithonStdout/onStderr/onExit - Uploading a large inline
build.shand running it withsudo finallycleanup with error logging onremove
Related guides
CI test runner
Simpler exec + exit code pattern
Code execution
Streaming and timeouts

