Overview
Coding Mode is a specialized agent mode that enables AI-powered web application development directly in the browser. When a user selects the Website category on the home page, Zeus enters Coding Mode — the AI writes code in a remote sandbox, and changes appear in real-time via an iframe-based live preview panel. This mode is powered by a configurable Sandbox Provider (E2B / OpenSandbox / Daytona) with a pre-installed Next.js 15 + Tailwind CSS + shadcn/ui tech stack.Architecture
Key Components
| Component | Location | Role |
|---|---|---|
| Sandbox Template | ai-backend/sandbox-templates/e2b/nextjs/ or sandbox-templates/opensandbox/ | Pre-built sandbox image with Next.js + deps |
| Coding Sandbox Tools | ai-backend/src/utils/tools/built_in/coding_sandbox.py | File operations and shell execution in sandbox |
| Coding Mode Prompt | ai-backend/src/repository/prompts/modes/coding_mode.md | System prompt for coding behavior |
| CodingPreview | web/src/components/agent/coding-preview/ | Iframe-based live preview component |
| codingStore | web/src/store/codingStore.ts | Zustand store for preview URL and sandbox state |
Sandbox Templates
To avoid slow startup times from runningnpm install on every session, Zeus uses pre-built sandbox templates that include:
- Node.js 22
- pnpm (global install)
- Next.js 15 (App Router, TypeScript, Tailwind CSS, ESLint, src dir)
- shadcn/ui (commonly used components pre-installed)
- Extra deps: lucide-react, framer-motion, clsx, tailwind-merge
- Code intelligence tools: typescript, typescript-language-server, pyright, @biomejs/biome (globally pre-installed for LSP diagnostics and CLI linting)
- Start command:
npx next dev --turbo(waits for port 3000)
E2B Template
OpenSandbox Image
Template Files (E2B)
| File | Purpose |
|---|---|
template.ts | E2B template definition (base image, install steps, start command) |
build.ts | Production build script |
build.dev.ts | Development build script |
files/page.tsx | Default landing page scaffold |
files/layout.tsx | Root layout with Inter font |
files/globals.css | Global styles with shadcn CSS variables |
Coding Sandbox Tools
When in Coding Mode, the agent has access to a dedicated set of tools that operate on the sandbox filesystem:| Tool | Description |
|---|---|
coding_write_file | Create or overwrite files in the project. Supports upsert — Next.js HMR auto-refreshes the preview. |
coding_read_file | Read file contents from the project. |
coding_grep | Search file contents using regex patterns (similar to grep/ripgrep). Excludes node_modules, .next, .git. |
coding_exec_sh | Execute shell commands in the project directory (e.g., pnpm add dayjs). |
coding_list_files | List project directory structure (excludes node_modules, .next, .git). |
sandbox_* tools (which are Python-oriented). The coding tools always operate on the /home/user/project/ directory inside the sandbox container.
Code Intelligence (LSP)
In Agent mode, Zeus provides thelsp tool for code intelligence, supporting:
| Operation | Description |
|---|---|
diagnostics | Get type errors and warnings for a file (like tsc --noEmit) |
definition | Jump to a symbol’s definition |
references | Find all references to a symbol |
hover | Get type information and documentation for a symbol |
document_symbols | List all symbols in a file |
workspace_symbols | Search for symbols across the project |
write and edit tools automatically run CLI linters (tsc, pyright, biome, eslint) after saving files, appending diagnostics to the tool output.
Mode Flow
Entry Point
- User selects the Website category on the Home page
HomeChatInputstoreszeus_pending_mode = 'coding'in sessionStorage- User submits a query, project and session are created
- Navigation to chat page occurs
Chat Page Initialization
- Chat page reads
zeus_pending_modefrom sessionStorage - Sets
chatStore.settings.mode = 'coding' - Clears the sessionStorage key
- Right panel renders
CodingPreviewinstead ofWorkspace
Backend Flow
- Agent service detects
mode == 'coding' - Initializes coding sandbox via
init_coding_sandbox()(useszeus-nextjstemplate) - Retrieves preview URL from sandbox (
sandbox.get_host(3000)) - Sends
coding_readySSE event withpreview_urlandsandbox_id - Injects
CODING_SANDBOX_TOOLSinto agent tool list - Loads
coding_mode.mdsystem prompt - Agent begins processing user request with coding tools
Frontend SSE Handling
stream-processor.tsreceivescoding_readyevent- Updates
codingStorewith preview URL and sandbox ID CodingPreviewcomponent renders iframe with the preview URL- Subsequent file writes trigger Next.js HMR — iframe auto-refreshes
Preview Panel
TheCodingPreview component provides:
- Iframe display of the running Next.js dev server
- Live indicator showing dev server status (green dot)
- Refresh button to manually reload the preview
- Open in new tab button for full-screen viewing
- Loading state while the sandbox initializes
- Collapsed state when the panel is minimized
Session Isolation
Zeus ensures that workspace state (sandbox files, website preview, tool executions, todos, agent trajectories) is fully isolated per chat session. Switching between conversations never leaks data from one session into another.Mechanism
The workspace state is managed bytrajectoryStore, which maintains an in-memory cache of SessionWorkspaceSnapshot objects keyed by session ID:
- Save / Restore: When the user navigates away from session A to session B, session A’s full workspace state is saved into
_sessionCache. If session B has a cached snapshot, it is instantly restored; otherwise a clean workspace is initialized. - SSE Session Guard: SSE event streams from the backend are not aborted when switching sessions (to allow the backend agent to continue executing in the background). Instead, a guard in
stream-processor.tschecks each incoming event’s session ID against_currentSessionId. Events belonging to a background session are still consumed and saved to the database viaRealtimeEventSaver, but all store updates (UI state changes) are skipped. - State Recovery: When the user returns to a previous session, the cached snapshot provides instant workspace restoration. Additionally,
loadEventsFromDbrebuilds the full state from persisted events, including any work the agent completed while the session was in the background.
Background Agent Execution
When a user switches away from a session where the agent is actively executing:- The SSE stream continues consuming events (the backend
StreamingResponsegenerator is not interrupted). - The backend sandbox stays alive —
sandbox_manager.set_session()calls_detach_unlocked(), which clears the in-memory provider reference without killing the container. - Events are persisted to the database by
RealtimeEventSaverregardless of whether the session is in the foreground. - When the user returns, the sandbox can be reconnected via its
sandbox_idstored in Redis.
Sandbox ID
ThesandboxId is part of the session-scoped workspace snapshot. Each session maintains its own sandbox identity, and switching sessions automatically saves and restores the correct sandboxId.
Tool Injection & Mode Filtering
Coding mode has its own tool set that replaces the standard sandbox tools:| Tool Category | Agent Mode | Ask Mode | Plan Mode | Coding Mode |
|---|---|---|---|---|
| Filesystem (read/write) | All | Read-only | Read-only | Disabled |
| TodoList | All | All | All | All |
| Memory | Read/write | Disabled | Read-only | Read/write |
| RAG | All | Read-only | All | All |
| Sandbox (Python) | All | Disabled | Disabled | Disabled |
| LSP (Code Intelligence) | All | Disabled | Disabled | Disabled |
| Coding Sandbox | Disabled | Disabled | Disabled | All |
| Web Search | All | All | All | All |
| MCP/OAuth | All | Read-only | Read-only | All |
| Browser/Desktop | All | Disabled | Disabled | Disabled |
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
SANDBOX_PROVIDER | Sandbox provider type | e2b |
SANDBOX_TIMEOUT | Sandbox timeout in seconds | 3600 |
E2B_API_KEY | E2B API key (required for E2B provider) | — |
E2B_SANDBOX_TEMPLATE | E2B template name | zeus-nextjs |
OPENSANDBOX_API_URL | OpenSandbox server URL (required for OpenSandbox provider) | http://localhost:8880 |
OPENSANDBOX_IMAGE | OpenSandbox sandbox image | zeus-base:latest |
Dependencies
Python (ai-backend):e2b— E2B cloud sandbox provideropensandbox-sdk— Alibaba OpenSandbox self-hosted sandbox provider (optional)
e2b— For building E2B custom templatesdotenv— Environment variable loading
Deployment
After building a project in Coding Mode, Zeus supports deploying it to production via the Deploy API. Three deployment targets are available:Vercel
Deploy the sandbox project to Vercel using their REST API.| Field | Type | Description |
|---|---|---|
sandbox_id | string | The active E2B sandbox ID |
vercel_token | string | Your Vercel API token |
project_name | string (optional) | Vercel project name (defaults to zeus-<sandbox_id>) |
node_modules, .next, .git), upload to Vercel API, return the deployment URL.
Server (SSH)
Deploy to your own server via SSH + rsync, then run a Docker-based deploy script.| Field | Type | Description |
|---|---|---|
sandbox_id | string | The active E2B sandbox ID |
server_host | string | Server hostname or IP |
server_port | int | SSH port (default: 22) |
server_user | string | SSH username |
server_password | string | SSH password |
server_path | string | Deployment path on server |
web_port | int | Web access port (default: 4000) |
deploy/script/deploy-saas.sh for containerized deployment.
Freestyle
Deploy using the Freestyle API for persistent preview URLs (*.style.dev).
| Field | Type | Description |
|---|---|---|
sandbox_id | string | The active E2B sandbox ID |
session_id | string | Session ID (used for consistent domain mapping) |
custom_domain | string (optional) | Custom domain override |
Deploy Environment Variables
| Variable | Description | Default |
|---|---|---|
FREESTYLE_API_KEY | Freestyle API key (required for Freestyle deploy) | — |