Required environment variable
Sandbox lifecycle
Check for an existing sandbox
When the Inngest function runs, it first checks whether the project already has a
sandboxId stored in the database.inngest/functions.ts
Connect or create
If a
sandboxId exists, the function reconnects to the running sandbox. Otherwise it creates a new one from the forgeai-v1 template and saves the ID to the project record.inngest/functions.ts
One sandbox is shared across all agent runs for the same project. Reconnecting resets the timeout, keeping the sandbox alive for another hour.
Agent uses the sandbox via tools
The coding agent interacts with the sandbox through four tools. All file paths are resolved relative to the project root.
lib/sandbox.ts
Sandbox tools
The coding agent has access to four tools that operate directly inside the sandbox:terminal — run shell commands
terminal — run shell commands
Executes arbitrary shell commands inside the sandbox. Used to install npm packages, run build commands, or inspect the environment.
createOrUpdateFiles — write files
createOrUpdateFiles — write files
Writes one or more files to the sandbox and updates the in-memory files map in network state. File paths are resolved against
/home/user/project.readFiles — read files
readFiles — read files
Reads one or more files from the sandbox and returns their contents as a JSON array of
{ path, content } objects.unsplashImage — download images
unsplashImage — download images
Searches Unsplash, downloads a matching photo, and saves it to
/public/assets/unsplash inside the sandbox. Returns the local public path and photographer attribution data.Requires
UNSPLASH_API_KEY in addition to E2B_API_KEY. The agent uses curl inside the sandbox to download images, so no file is transferred through the Next.js server.Sandbox reference
| Property | Value |
|---|---|
| Template | forgeai-v1 |
| Project root | /home/user/project |
| Dev server port | 3000 |
| Timeout | 1 hour (3,600,000 ms) |
| Image assets path | /public/assets/unsplash |
| Scope | One sandbox per project |
Related pages
Inngest background jobs
The Inngest function that manages sandbox creation and invokes the agent.
Live preview
How the sandbox URL is surfaced in the ForgeAI UI.