Back to Library
Beginner
Developer Tools
Coding
Security

Run AI-Generated Code in a Sandbox Instead of Your Laptop

Give an AI assistant's generated scripts somewhere safe to run before they ever touch your own machine, using a disposable cloud sandbox instead of a permissions system you'd have to build yourself.

Time Required

30-45 minutes, one-time setup

Expected Result

A repeatable habit of testing AI-generated code inside a disposable cloud sandbox first, with your local machine and files never directly exposed to code you haven't reviewed yet.

Recommended Tools

1

Get an E2B API Key and Install the SDK

Sign up for E2B's free tier (100 sandbox-hours a month) and install the Python or JavaScript SDK. This is the only setup step: no server to provision, no infrastructure to manage.

E2B
2

Ask an AI Assistant for a Short Script

Ask Claude or ChatGPT to write a small script for a real task, like renaming a batch of files or parsing a CSV. Don't run it locally yet; treat it as untested code from here on.

Claude
3

Run It Inside a Sandbox First

Spin up an E2B sandbox and execute the script there instead of on your machine. E2B's sandboxes start in under 150ms, so this adds almost no friction to the normal ask-then-run loop.

E2B
4

Feed the Real Output Back to the AI

Copy the sandbox's actual stdout and any error output back to the assistant and ask it to fix what's wrong. Re-run the fixed version in the same sandbox rather than starting a new one, so you're iterating on real results, not guesses.

Claude
E2B
5

Know What the Sandbox Does and Doesn't Protect You From

A sandbox isolates code from your laptop, not from your accounts. If the script uses a real API key or credential you gave it, it can still send a real email or spend real money from inside the sandbox. Treat any credential you hand to sandboxed code as already in use, not just being tested, and confirm the sandbox actually tears down afterward since E2B's compute is metered past the free tier.

Tools Used In This Workflow

Related Workflows

From the Blog