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 usecode (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
execreturns an envelope whose payload holdsstdout,stderr, andexitCode/exit_code. In TypeScript you readresult.data. In Pythonresult.datais already the innerExecResponseData(single.data, not nested twice).timeout: You set a generoustimeout(seconds) so large installs do not abort mid-run.cwdandenv: You set the working directory and inject secrets (test tokens) throughenv/envVarsinstead 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 firstexec step.
Step 1: Create a sandbox for the job
You name the sandbox so you can correlate CI logs (for exampleci- + build id).
Step 2: Run the test command
You keep the command one logical unit (singleexec) 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 onexit_code.
Step 4: Clean up
You remove the sandbox in afinally 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
/appis empty: use file APIs orexecwithgit clonedepending on your security model. - You avoid echoing secrets in
commandstrings; you pass them throughenv. - You cap parallel sandboxes per org if you pay per sandbox minute.
Related guides
Code execution
Exec options and streaming
Custom images
Pre-baked toolchains

