|
1 | | -# Sandbox templates |
| 1 | +# Code0 Sandbox Templates (standalone) |
2 | 2 |
|
3 | | -This repo contains E2B sandbox templates used by the app to spin up ephemeral environments for each project. |
| 3 | +Standalone E2B sandbox templates used by the Code0 app to spin up ephemeral environments per project. |
4 | 4 |
|
5 | | -## Structure |
6 | | -- `nextjs/` |
7 | | - - `e2b.Dockerfile` — Docker build for the template image |
8 | | - - `e2b.toml` — Template metadata (team, name/ID, start command) |
9 | | - - `compile_page.sh` — Start script executed inside the sandbox (path: `/compile_page.sh`) |
| 5 | +Once published, the app can create sandboxes in E2B Cloud (no local Docker required at runtime). |
10 | 6 |
|
11 | | -## Requirements |
12 | | -- E2B account + API key (E2B_API_KEY) |
13 | | -- Docker Desktop (only needed to build/publish templates) |
14 | | -- Node.js (to run the E2B CLI via npx or global install) |
| 7 | +## Templates |
| 8 | +- `nextjs-shadcn` — Next.js 15 + shadcn/ui baseline. |
| 9 | +- `nextjs-radixui` — Next.js 15 + Radix UI baseline. |
15 | 10 |
|
16 | | -Once a template is published, the app can create sandboxes from E2B Cloud without Docker running locally. |
| 11 | +Each template folder contains: |
| 12 | +- `e2b.Dockerfile` — how the template image is built. |
| 13 | +- `e2b.toml` — template metadata (team, name/ID, CPU/RAM, start command). |
| 14 | +- `compile_page.sh` — start script executed inside the sandbox at `/compile_page.sh`. |
17 | 15 |
|
18 | | -## Configure env (root .env) |
19 | | -Set one of (ID is preferred): |
| 16 | +## Prerequisites |
| 17 | +- E2B account + API key (`E2B_API_KEY`). |
| 18 | +- E2B CLI (use `npx e2b@latest` or install globally with `npm i -g e2b`). |
| 19 | +- Docker Desktop (for building/publishing templates). |
| 20 | +- Node.js (to run scripts in this repo). |
| 21 | + |
| 22 | +## Configure (env) |
| 23 | +Set your API key before building/publishing: |
| 24 | + |
| 25 | +PowerShell |
| 26 | +``` |
| 27 | +$env:E2B_API_KEY = "<your_e2b_api_key>" |
| 28 | +``` |
| 29 | + |
| 30 | +In the app that consumes templates, set one of (ID is preferred): |
20 | 31 | - `E2B_TEMPLATE_ID=<template_id>` |
21 | 32 | - or `E2B_TEMPLATE_NAME=<template_name>` |
22 | 33 | - or `E2B_TEMPLATE=<template_name>` |
23 | | -Also set `E2B_API_KEY=<your_key>`. |
24 | 34 |
|
25 | | -Sandbox names are derived from each project’s name automatically. |
| 35 | +Sandbox names are typically derived from each project’s name. |
26 | 36 |
|
27 | | -## Build & publish |
28 | | -Windows PowerShell examples: |
| 37 | +## Build & publish (per template) |
| 38 | +PowerShell examples: |
29 | 39 |
|
30 | | -- Using npx (no install): |
| 40 | +Using npx (no global install): |
31 | 41 | ``` |
32 | 42 | $env:E2B_API_KEY = "<your_e2b_api_key>" |
33 | | -cd sandbox\nextjs |
| 43 | +cd .\nextjs-shadcn\ |
| 44 | +npx e2b@latest template build |
| 45 | +npx e2b@latest template publish |
| 46 | +
|
| 47 | +cd ..\nextjs-radixui\ |
34 | 48 | npx e2b@latest template build |
35 | | -npx e2b@latest templates publish |
| 49 | +npx e2b@latest template publish |
36 | 50 | ``` |
37 | 51 |
|
38 | | -- Or global install: |
| 52 | +Or with global CLI: |
39 | 53 | ``` |
40 | 54 | npm i -g e2b |
41 | 55 | $env:E2B_API_KEY = "<your_e2b_api_key>" |
42 | | -cd sandbox\nextjs |
43 | | -e2b template build |
44 | | -e2b templates publish |
| 56 | +cd .\nextjs-shadcn\ ; e2b template build ; e2b template publish |
| 57 | +cd ..\nextjs-radixui\ ; e2b template build ; e2b template publish |
| 58 | +``` |
| 59 | + |
| 60 | +After publishing, the CLI prints the `template_id`. Use that in your app `.env` as `E2B_TEMPLATE_ID`. |
| 61 | + |
| 62 | +## Build & publish all templates (script) |
| 63 | + |
| 64 | +This repo includes a helper script to build/publish every template under this folder: |
| 65 | + |
| 66 | +``` |
| 67 | +node ./scripts/build-and-publish.mjs # build + publish all |
| 68 | +node ./scripts/build-and-publish.mjs --mode build # build only |
| 69 | +node ./scripts/build-and-publish.mjs --mode publish # publish only |
| 70 | +``` |
| 71 | + |
| 72 | +Requirements: E2B CLI available on PATH (use `npx e2b@latest` or global `e2b`). On Windows, the script spawns with shell support. |
| 73 | + |
| 74 | +## Resource configuration |
| 75 | +You can set CPU/RAM per template in `e2b.toml`: |
| 76 | + |
| 77 | +``` |
| 78 | +cpu_count = 8 |
| 79 | +memory_mb = 8192 |
| 80 | +``` |
| 81 | + |
| 82 | +Or override at build time: |
| 83 | + |
| 84 | +``` |
| 85 | +e2b template build --cpu-count 8 --memory-mb 8192 |
45 | 86 | ``` |
46 | | -After publishing, copy the `template_id` from the CLI output and put it in `.env` as `E2B_TEMPLATE_ID`. |
47 | 87 |
|
48 | 88 | ## Start command & script path |
49 | | -- `e2b.toml`: `start_cmd = "/compile_page.sh"` |
50 | | -- `e2b.Dockerfile` copies and makes it executable: |
| 89 | +- `e2b.toml` sets: `start_cmd = "/compile_page.sh"` |
| 90 | +- `e2b.Dockerfile` ensures the script exists and is executable: |
51 | 91 | - `COPY compile_page.sh /compile_page.sh` |
52 | 92 | - `RUN chmod +x /compile_page.sh` |
53 | | -Update both if you rename or move the script. |
| 93 | + |
| 94 | +Always use the absolute path (`/compile_page.sh`) and LF line endings inside the image. |
| 95 | + |
| 96 | +## CI/CD (GitHub Actions example) |
| 97 | +``` |
| 98 | +name: Publish E2B Templates |
| 99 | +on: |
| 100 | + workflow_dispatch: |
| 101 | + push: |
| 102 | + branches: [ main ] |
| 103 | +jobs: |
| 104 | + publish: |
| 105 | + runs-on: ubuntu-latest |
| 106 | + steps: |
| 107 | + - uses: actions/checkout@v4 |
| 108 | + - uses: actions/setup-node@v4 |
| 109 | + with: |
| 110 | + node-version: 20 |
| 111 | + - name: Install E2B CLI |
| 112 | + run: npm i -g e2b |
| 113 | + - name: Build & Publish All Templates |
| 114 | + env: |
| 115 | + E2B_API_KEY: ${{ secrets.E2B_API_KEY }} |
| 116 | + run: | |
| 117 | + cd sandbox |
| 118 | + node ./scripts/build-and-publish.mjs |
| 119 | +``` |
54 | 120 |
|
55 | 121 | ## Troubleshooting |
56 | | -- Docker daemon not running: start Docker Desktop; WSL2 & Linux containers enabled. Test with `docker version` and `docker run hello-world`. |
57 | | -- Script not found / exit 127: ensure `start_cmd` uses the absolute path and the script has LF line endings on Windows. |
58 | | -- Template 404: ensure the template exists in your E2B team and `.env` points to the correct ID/name. |
| 122 | +- Docker daemon not running: start Docker Desktop; WSL2 & Linux containers enabled. Verify with `docker version` and `docker run hello-world`. |
| 123 | +- Exit 127 / script not found: ensure `start_cmd` is absolute and the script has executable bit and LF line endings. |
| 124 | +- Template 404: ensure the template exists in the correct E2B team and you’re using the right `template_id` or name. |
| 125 | +- Nested app folder: both Dockerfiles build in `/tmp/app` and copy to `/home/user` to avoid `nextjs-app` nesting. |
| 126 | + |
| 127 | +## Security & license |
| 128 | +See `SECURITY.md` and `LICENSE`. |
0 commit comments