# LAB 1: Your first disposable box

Goal: stand up a sandbox that runs code you did not write, then throw the sandbox away.
Time: about 20 minutes.
You need a laptop for these labs (it is on the ticket). Phone only today? Pair up with a
neighbor and drive together.

You have two paths. Pick one.

- **Path A: Docker.** Best if you brought a laptop with Docker installed. No account needed.
- **Path B: e2b.** Best if you have no Docker. It is a cloud sandbox with a free tier.
  Sign up at e2b.dev, it takes about two minutes, and the free credit covers today's lab.
  Already have a key? Use it. If signing up blocks you, ask a host. We never post keys on slides.

## Path A: Docker

1. Check Docker is alive:
   ```
   docker run --rm hello-world
   ```
2. Run a piece of "untrusted" code inside a throwaway container. No network. Capped memory:
   ```
   docker run --rm --network none --memory 256m python:3.11-slim python -c "print(2 + 2)"
   ```
3. Look at the flags. `--rm` deletes the container when it exits. `--network none` cuts the
   internet. `--memory 256m` caps RAM. Those three flags matter most. (The example script
   you run in step 5 adds one more, `--cpus 0.5`, a CPU cap. Same idea.)
4. Prove the box is gone:
   ```
   docker ps -a
   ```
   The container from step 2 is not in the list.
5. Now run the same thing from Python. Open `examples/01_docker_sandbox.py`, read the
   docstring, then run it from inside the examples folder:
   ```
   cd examples
   python 01_docker_sandbox.py
   ```

**CHECKPOINT:** you know it worked when step 2 prints `4`, step 4 shows no leftover
container, and the example script prints the container output and exits clean.

## Path B: e2b (no Docker needed)

1. Get your key: sign up free at e2b.dev (about two minutes), then copy the API key from
   the dashboard. Already have one? Use it. Set it in your shell:
   ```
   set E2B_API_KEY=<the key>        (Windows)
   export E2B_API_KEY=<the key>     (Mac / Linux)
   ```
2. Install the SDK:
   ```
   pip install e2b-code-interpreter
   ```
3. Open `examples/02_e2b_sandbox.py` and read the docstring. Run it from inside the
   examples folder:
   ```
   cd examples
   python 02_e2b_sandbox.py
   ```
4. Run it once WITHOUT the key set (open a fresh shell). See how it refuses politely and
   tells you what it would have done. That guard pattern is worth copying.

**CHECKPOINT:** you know it worked when the script prints output that came back from a
cloud sandbox, and the no-key run exits clean with a clear message instead of a stack trace.
