← All use cases
AI agents & LLM tools

How to run AI-generated code safely (without risking your machine)

July 28, 2026

The problem

LLMs write code shaped by their inputs — and inputs can be adversarial. Prompt injection means the code your agent generates isn't always the code you'd have written. Running it with exec(), eval(), or a subprocess on your own machine hands it your filesystem, your environment variables (read: API keys), and your network. The worst case isn't a crash. It's exfiltration.

The fixes that don't work

  • "I'll review the code first" — fine for a demo, impossible for an agent generating code in a loop
  • exec() with restricted builtins — sandbox escapes from restricted Python are an entire genre
  • DIY Docker — better, but containers share the host kernel, escapes exist, and now you're maintaining images, timeouts, cleanup, and scaling yourself

The pattern that works

Run every generated snippet in a disposable, hardened sandbox: no network access, read-only base filesystem, strict CPU/memory/time limits, destroyed after every run. gVisor puts a userspace kernel between the untrusted code and the host, so even a kernel-level exploit hits a decoy.

What that looks like in practice

One call:

curl https://api.cinch.codes/run \
  -H "Authorization: Bearer $CINCH_KEY" \
  -H "Content-Type: application/json" \
  -d '{"code": "print(2 + 2)", "language": "python"}'

Response:

{
  "stdout": "4",
  "stderr": "",
  "exitCode": 0,
  "timedOut": false,
  "durationMs": 287
}

The agent loop becomes: model generates code → code goes to the sandbox → stdout/stderr come back to the model → repeat. Your infrastructure never touches the code. Each run is a brand-new box, so include everything the code needs in each call.

What it costs

Cinch bills $0.10 per sandbox-hour, by the millisecond — a 300ms run costs about eight ten-thousandths of a cent. No subscription, no monthly floor. New accounts get $1 free (~10 sandbox-hours), and there are Python (pangolin-sdk) and JavaScript (@cinch-codes/pangolin) SDKs plus an MCP server for agent frameworks.

Try it at cinch.codes. Building something real? Up to $1,000 in credits: cinch.codes/builders.

Try it yourself

Run untrusted code in a secure sandbox with one API call. Free to start.

Comments, questions, concerns? Email us at hello@cinch.codes