kosa8 / Best sandboxes

Best sandbox · CI/CD

The best sandbox for CI/CD pipelines that run AI-generated code

Updated

A CI runner holds deploy keys, registry tokens and a network path to your infrastructure, which is exactly what a pull request from an AI agent or an outside contributor should not touch. The best sandbox for that step is one the runner calls out to: a fresh microVM per job with nothing secret inside, deleted when the step ends. kosa8 Cloud does it with three HTTP calls from any CI system, and a self-hosted runner can use kosa8 locally.

01What a CI step needs from a sandbox

Most CI already isolates jobs from each other. What it does not do is isolate the code under test from the job's own secrets: the test step runs in the same environment that later pushes images and deploys.

When the code was written by an AI agent, or comes from a fork, you want the test step somewhere else: started fresh, with no credentials, a network you choose, a time limit, an exit code the pipeline can act on, and a cleanup that happens even when the job is cancelled.

02Checklist for choosing one

  • Callable from any CI. Plain HTTP or a single binary, no special runner.
  • Nothing secret inside. The sandbox gets the code, not the pipeline's tokens.
  • Exit code and output back. So a failing test fails the pipeline.
  • Long commands. Test suites that run for minutes, streamed back.
  • Guaranteed cleanup. A cancelled job must not leave machines running.
  • Per-second billing. CI steps are short and bursty.
  • A record. Which job ran what, for later review.

03How kosa8 meets it

Add a kosa8 Cloud API key as a CI secret (KOSA8_API_KEY). The job creates a sandbox, runs the tests with "stream": true so a long suite is not held to the 90-second limit of a plain exec, and deletes the sandbox in a step that always runs. This is GitHub Actions; the same curl calls work in any CI.

.github/workflows/sandboxed-tests.yml
jobs:
  sandboxed-tests:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    env:
      KOSA8_API_KEY: ${{ secrets.KOSA8_API_KEY }}
      API: https://api.kosa8.com/v1/sandboxes
    steps:
      - name: Create a sandbox
        run: |
          id=$(curl -sf -X POST "$API" -H "Authorization: Bearer $KOSA8_API_KEY" \
            -H 'Content-Type: application/json' -d '{"template":"python"}' | jq -r .sandbox.id)
          echo "SBX=$id" >> "$GITHUB_ENV"
      - name: Run the tests inside it
        run: |
          body=$(jq -n --arg c "cd /workspace && python3 -c \"import io,tarfile,urllib.request; tarfile.open(fileobj=io.BytesIO(urllib.request.urlopen('https://codeload.github.com/${{ github.repository }}/tar.gz/${{ github.sha }}').read())).extractall('src')\" && cd src/* && python3 -m pip install -q -r requirements.txt pytest && python3 -m pytest -q" \
            '{cmd: ["sh", "-c", $c], stream: true}')
          curl -sfN -X POST "$API/$SBX/exec" -H "Authorization: Bearer $KOSA8_API_KEY" \
            -H 'Content-Type: application/json' -d "$body" > out.ndjson
          jq -rj 'select(.stream) | .data | @base64d' out.ndjson
          exit "$(jq -r 'select(.done) | .exit' out.ndjson)"
      - name: Delete the sandbox
        if: always()
        run: curl -s -X DELETE "$API/$SBX" -H "Authorization: Bearer $KOSA8_API_KEY"

The streamed answer is NDJSON: lines of {"stream":"stdout","data":"<base64>"} and a final {"done":true,"exit":N}. The example downloads a public repository's tarball; keep untrusted text such as branch names and PR titles out of the command, because the CI system pastes expressions in before the shell runs.

On a self-hosted Linux runner with KVM you can skip the cloud: install kosa8 there and run the step in an ephemeral local sandbox with kosa8 sandbox create ci --ephemeral --egress-allow pypi.org --egress-allow files.pythonhosted.org.

04When another option fits better

  • Your own trusted code. Hosted CI runners already give each job a fresh VM. If the code is yours and the job holds no secrets you worry about, a second sandbox adds little.
  • Container jobs. Running the test step in a separate container without the secrets mounted is a cheaper middle ground; it shares the runner's kernel.
  • Separate CI for forks. Many projects already run fork pull requests without secrets. kosa8 is useful when the same job must also hold secrets for later steps.

05FAQ

Is there a kosa8 GitHub Action?

kosa8's docs describe a kosa8/sandbox action built on the same three calls. The plain curl version on this page works today in GitHub Actions, GitLab CI, Buildkite or Jenkins, with curl and jq as the only tools.

What happens if the job is cancelled?

The delete step runs with if: always(). A sandbox that is left anyway goes to sleep after the organization's idle timer, and you can list and remove leftovers with GET /v1/sandboxes and DELETE.

Why stream the exec?

An exec answered as one JSON object runs at most 90 seconds, then returns 504 exec_timeout. With "stream": true the output arrives as it is printed and the command is not held to that limit.

Does the sandbox see my CI secrets?

Only what you put in the command or its env. The example passes none.

06Get started

Install kosa8 on a Mac, Linux or Windows (WSL2) machine, or make an account and run the same sandboxes on kosa8 Cloud.

07Sources

Related

Updated 2026-11-14