Overview
Magpie supports two sandbox execution modes:- Local — commands run via
std::process::Command(default) - Daytona — commands run in remote Daytona sandboxes via REST API (feature-gated)
Sandbox Trait
All command execution routes through theSandbox trait:
crates/magpie-core/src/sandbox/mod.rs:62-90
DaytonaConfig
Configuration for creating Daytona sandboxes:crates/magpie-core/src/sandbox/mod.rs:45-60
Environment Variables
Basic Settings
Daytona API key for authentication.Example:Note: When set, all pipeline commands execute inside a Daytona sandbox instead of locally.
Daytona API base URL.Example:
Daytona organization ID (for multi-org accounts).Example:
Sandbox size class. Available options depend on your Daytona plan:
small— 2 CPU, 4 GB RAMmedium— 4 CPU, 8 GB RAMlarge— 8 CPU, 16 GB RAM
Snapshots (Pre-built Images)
Daytona snapshot name to create sandboxes from. Snapshots are pre-built images with:Performance:
- Repository cloned
- Dependencies installed (e.g.
cargo fetch,npm install) - Services configured
- Cold clone + build: 5-10 minutes
- Snapshot-based creation: 5-10 seconds
Comma-separated Use Case: Pass API keys and secrets to sandboxes without baking them into snapshots.Parsing:Source:
KEY=VALUE pairs to inject into sandboxes at creation time.Example:crates/magpie-cli/src/main.rs (DAYTONA_ENV parsing)Persistent Volumes (Build Cache)
Persistent volume UUID for build cache. Preserves compiled artifacts across sandbox instances:Performance: Speeds up builds by 3-10x (Rust incremental builds, npm/cargo cache hits).
- Rust:
target/ - Node.js:
node_modules/,.next/ - Python:
.venv/,__pycache__/
Mount point for the persistent volume inside the sandbox.Example:Note: Must be set if
DAYTONA_VOLUME_ID is set.Creating Sandboxes
Cold Creation (Clone + Build)
- Create sandbox via Daytona API
- Clone repo with
gh repo clone my-org/my-repo /workspace/my-org-my-repo - Sandbox is ready for command execution
crates/magpie-core/src/sandbox/daytona.rs:33-88
Snapshot-based Creation (Fast)
- Create sandbox from pre-built snapshot
- Wait for sandbox to reach
Startedstate (large images: up to 5 minutes) - Configure git (
safe.directory, user identity,gh auth setup-git) - Fix workspace permissions
crates/magpie-core/src/sandbox/daytona.rs:90-221
Warm Pool
The warm pool maintains pre-provisioned sandboxes for fast acquisition.WarmPoolConfig
How many sandboxes to keep per repo.Example:
pool_size: 3 maintains 3 idle sandboxes for each configured repo.How often (seconds) to refresh idle workspaces with
git fetch + build check.Example: refresh_interval_secs: 300 (5 minutes)Per-repo configurations (see below).
crates/magpie-core/src/sandbox/pool.rs:113-124
RepoPoolConfig
Short repo name (e.g.
"bnplx").Full repo name with org (e.g.
"niteshballa/bnplx").Daytona snapshot to create sandboxes from.Example:
"bnplx-snapshot"Sandbox size override (per-repo).Example:
"large" for heavy builds, "small" for docs-only repos.Branch to track for refresh.Example:
"main"Command to verify build health during refresh.Example:
Some("cargo check".to_string())Persistent volume UUID for this repo.
Volume mount path for this repo.
Repo-specific environment variables (merged with pool-level env vars).
crates/magpie-core/src/sandbox/pool.rs:86-108
Pool Lifecycle
1. Provisionpool_size sandboxes per repo from snapshots, then runs post-provision commands (service start, migrations, etc.).
Source: crates/magpie-core/src/sandbox/pool.rs:161-198
2. Acquire
None if the pool is exhausted.
Source: crates/magpie-core/src/sandbox/pool.rs:295-309
3. Release
crates/magpie-core/src/sandbox/pool.rs:314-336
4. Refresh Loop
git fetch + build check on all idle workspaces.
Source: crates/magpie-core/src/sandbox/pool.rs:341-428
5. Shutdown
crates/magpie-core/src/sandbox/pool.rs:431-457
Example Configurations
Local Execution (Default)
Daytona Cold Clone
Daytona Snapshot (Fast)
Daytona with Persistent Volume
Warm Pool (Code)
Troubleshooting
Sandbox Creation Timeout
Cause: Large snapshot images (4+ GB) can take up to 5 minutes to start. Fix: The pipeline waits up to 300 seconds. If this isn’t enough, check Daytona API logs.Git Operations Fail
Cause: Snapshot-based sandboxes needsafe.directory configured.
Fix: DaytonaSandbox::create_from_snapshot handles this automatically via setup commands.
Source: crates/magpie-core/src/sandbox/daytona.rs:172-194
Permission Denied
Cause: Snapshot image was built asroot but sandbox runs as daytona user.
Fix: Setup commands run sudo chmod -R 777 /workspace/magpie to fix ownership.
Important: Only chmod the top-level directory, NOT recursive on large dirs (triggers copy-on-write, fills disk).
Source: crates/magpie-core/src/sandbox/daytona.rs:160-182
Build Cache Miss
Cause: Persistent volume not attached. Fix: VerifyDAYTONA_VOLUME_ID and DAYTONA_VOLUME_MOUNT_PATH are set correctly.
Related Documentation
- Pipeline Configuration — Core pipeline settings
- Environment Variables — Complete env var reference