Originally published on sandscale.dev.
A pull request is a request to run someone else's code on your machine. CI has always worked this way: check out the branch, install dependencies, run the tests. The code that runs includes the test files, the build scripts, the install hooks of every new dependency, and anything the PR changed in your CI config.
That was already a risk with human contributors from outside the team. It gets bigger when an agent opens the PR, because nobody wrote the diff line by line and nobody necessarily read it. This post describes one way to run that code with Sandscale so a bad PR is a bad afternoon for one disposable box and not for your laptop or your CI runners.
What you are protecting against
Be specific about the threats, because the controls differ:
- Escape or damage: the code deletes files, fills the disk, or tries to attack whatever it runs on.
- Exfiltration: the code reads secrets from its environment and sends them somewhere.
- Persistence: something left behind by one run affects the next.
- Runaway cost or time: an infinite loop, a fork bomb or a hung process.
A sandbox does not decide whether the PR is good. It limits what a bad one can reach.
The setup
The plan is the same for every PR: start a fresh sandbox, put the PR's files in, run the tests, read the result, stop the sandbox.
Each Sandscale sandbox is a Firecracker microVM with its own kernel, not a container that shares a kernel with other work. A new one starts with the network off and goes away when you stop it. For the full picture, see Sandboxes and Security.
You need a personal API key with the sandboxes:create and sandboxes:use permissions. The Run code in a sandbox guide covers the key and the base URL:
API=https://api.sandscale.dev/api/v1/sandbox AUTH="Authorization: Bearer $SANDSCALE_API_KEY" The commands below follow that guide. Only the values change: the template, the time limit, the name and the command.
1. Start a sandbox with a short life
curl -X POST "$API/instances" -H "$AUTH" -H "Content-Type: application/json" \ -d '{"template_id": "builtin:node", "ttl_seconds": 900, "name": "pr-1234"}' Two choices here matter. ttl_seconds stops the sandbox by itself when it runs out, so a hung run cannot sit there for hours. And you name the box after the PR, so the audit log is easy to read later. Built-in templates include builtin:python, builtin:node, builtin:go and builtin:base, and curl "$API/launch-options" -H "$AUTH" lists the templates and options you can use.
Do not pass secret_refs or env with real credentials. The test run of an unreviewed PR should have no secrets at all. If a test genuinely needs one, give it a test-scoped key and read Give a run a secret first.
2. Bring the code in without opening the network
You do not need to give the sandbox network access to fetch the PR. Check out the PR's head on a machine you control and send the files from there.
For a whole folder, make a gzip tar archive of the checkout and upload it with POST /api/v1/sandbox/instances/{id}/project. It needs the sandboxes:use permission and takes an optional dir query parameter. The Sandboxes API reference lists its parameters and errors, such as project_too_large and invalid_project_archive.
For a single file, the guide shows the call. content is base64:
curl -X PUT "$API/instances/$ID/files" -H "$AUTH" -H "Content-Type: application/json" \ -d "{\"path\": \"/workspace/hello.py\", \"content\": \"$(printf 'print(\"hi\")' | base64)\"}" 3. Run the tests
curl -X POST "$API/instances/$ID/exec" -H "$AUTH" -H "Content-Type: application/json" \ -d '{"command": ["npm", "test"], "timeout_sec": 600}' The answer has exit_code, stdout, stderr, duration_ms, and timed_out and oom_killed flags. Those last two are useful signals when you review a PR: a test suite that hits the time limit or runs the box out of memory is telling you something.
If your project needs npm ci first, that needs the network. Sandboxes have no network unless your policy allows it. The create request has an optional network field, where empty or none means no network, and the launch options list the network modes you can choose. What a sandbox with network can reach is set by the egress_allowlist in your organization's sandbox policy, which PUT /api/v1/sandbox/policy replaces and which needs the sandboxes:write permission. Both are in the Sandboxes API reference, and what each plan allows is on pricing. The practical setup is an allowlist with your package registry and nothing else.
4. Read the results, then throw the box away
Read the output from the exec answer. To pull files out, such as a coverage report, list the directory and read what you need:
curl "$API/instances/$ID/files?path=/workspace" -H "$AUTH" GET .../project/changes returns what changed in the project since you uploaded it. Files can be up to 1 GiB each. Then stop the sandbox:
curl -X DELETE "$API/instances/$ID" -H "$AUTH" Nothing from this run carries over to the next one. The next PR gets a new sandbox from the template, with the same clean start.
What each control gives you
| Threat | What limits it |
|---|---|
| Escape or damage | Its own kernel per sandbox; you stop it and it is gone |
| Exfiltration | Network off by default; with an allowlist, only listed destinations; no secrets passed in |
| Persistence | A new sandbox per PR, nothing left over from the last one |
| Runaway time | ttl_seconds and timeout_sec |
| Runaway cost | Paused and idle time is free; you pay for awake vCPU-hours, and paid plans have spend caps (see pricing) |
Be honest about the limits of that table. A microVM boundary is strong, but it is not a promise that nothing can ever go wrong, and a PR can still print misleading test output. Treat the exit code and logs as untrusted input too.
When the PR comes from an agent
If an agent opened the PR, the agent had its own controls before the code ever reached review. Agent policy lets you allow, block or ask first for each tool call, for example asking before git push or gh pr create. With approvals, a named person approves or denies a call, and an approved call runs once. Nobody approves their own request.
Every sandbox, command, approval and change is written to the audit log, each entry chained to the one before it, so an edit shows. When someone asks "what ran for PR 1234?", you look it up.
One limit to know: DLP scans prompts and MCP tool calls, but files and output inside a sandbox are not scanned. Do not rely on DLP to catch a secret that untrusted code writes to a log. The way to keep secrets from leaking is not to put them in the box.
From an agent
If you would rather have your coding agent do this, Sandscale's MCP tools let it start sandboxes, run commands in them and stop them, with your sign-in and inside your policy. See the MCP server page and the MCP tools reference for how to connect it.
A short checklist
- Fresh sandbox per PR, named after it.
- Short
ttl_secondsand atimeout_secon every command. - No secrets, no
secret_refs. - Network off, or an allowlist with only your registry.
- Archive in, results out, then stop the box.
- Look at
timed_outandoom_killed, not only the exit code.
If you try this and a step does not match the docs, email developer@sandscale.dev.

