Skip to main content

Example: CI test runner

You use this pattern when continuous integration (or a scheduled job) must execute tests inside an isolated Linux environment. You treat the sandbox as a throwaway worker: you create it, you run one command (or a small script), you read the exit code, you delete the sandbox.

What you accomplish

You provision a sandbox with a system image. For most JS and Python CI jobs you use code (includes Node and Python). You use max when you need a Debian-style environment, or docker only when the pipeline needs Docker inside the VM. You run npm ci && npm test, pytest, or a bash driver script. You map exitCode === 0 / exit_code == 0 to pipeline success. You surface stderr in your CI logs when tests fail.

Concepts you use

  • exec returns an envelope whose payload holds stdout, stderr, and exitCode / exit_code. In TypeScript you read result.data. In Python result.data is already the inner ExecResponseData (single .data, not nested twice).
  • timeout: You set a generous timeout (seconds) so large installs do not abort mid-run.
  • cwd and env: You set the working directory and inject secrets (test tokens) through env / envVars instead of embedding them in the command string when you can.

Prerequisites

You completed Examples overview. You know which image contains your toolchain, or you install tools in the first exec step.

Step 1: Create a sandbox for the job

You name the sandbox so you can correlate CI logs (for example ci- + build id).

Step 2: Run the test command

You keep the command one logical unit (single exec) when possible so you capture one exit code for the whole suite. You increase timeout for npm ci plus tests.

Step 3: Python tests with pytest (variant)

You swap the command when your repo is Python-first. You still rely on exit_code.

Step 4: Clean up

You remove the sandbox in a finally block (or CI always step) so failures do not leak VMs.

Practices you should follow

  • You upload or clone source into the sandbox before you test if /app is empty: use file APIs or exec with git clone depending on your security model.
  • You avoid echoing secrets in command strings; you pass them through env.
  • You cap parallel sandboxes per org if you pay per sandbox minute.

Code execution

Exec options and streaming

Custom images

Pre-baked toolchains