Skip to main content
Vectra Guard’s sandbox system provides transparent, fast, and secure isolation for risky commands. It intelligently decides when to sandbox based on risk level and context.

Sandbox Modes

Vectra Guard supports three sandbox modes:
sandbox:
  enabled: true
  mode: always  # Maximum security
All commands run in sandbox
  • ✅ Maximum security out of the box
  • ✅ 10x speedup with caching enabled
  • ✅ Provable isolation for everything
  • ✅ Perfect for AI agents and untrusted code
vg exec "echo hello"        # → Sandbox (cached, fast)
vg exec "npm install"       # → Sandbox (cached, 10x faster)
vg exec "curl remote.com"   # → Sandbox (isolated)
vg exec "rm -rf /"          # → Blocked (critical)
Recommended: Use mode: always (default) for maximum security with intelligent caching for speed.

Cache Mounting: 10x Speedup

The caching magic that makes sandbox execution fast:

The Problem: Slow Repeated Installs

Without caching, every sandbox execution starts fresh:
# Without cache: SLOW ❌
vg exec "npm install express"
# → Creates fresh container
# → Downloads 50 packages from internet: 12.3s
# → Container destroyed

vg exec "npm install lodash"
# → Creates NEW fresh container
# → Downloads 30 packages AGAIN: 8.7s
# → Container destroyed

# Total wasted: ~21 seconds + repeated downloads

The Solution: Shared Cache Mounts

Vectra Guard mounts your host cache directories into the sandbox:
# WITH cache: FAST ✅
vg exec "npm install express"
# → Creates container
# → Mounts ~/.npm into container
# → Checks cache FIRST (most packages already there!)
# → Only downloads NEW/MISSING packages: 1.2s ⚡
# → Cache persists on host

vg exec "npm install lodash"  
# → Creates NEW container
# → Mounts SAME ~/.npm cache
# → Finds express deps ALREADY in cache!
# → Only downloads lodash: 0.8s ⚡
# → Everything reused!

# Total time: ~2 seconds (vs 21 seconds!)
# 🎉 10x FASTER

How Cache Mounting Works

┌──────────────────────────────────────────────────────┐
│                      Your Host Machine               │
├──────────────────────────────────────────────────────┤
│                                                       │
│  ~/.npm/ (Cache Root)                                │
│    ├── express@4.18.0/      ← Already downloaded     │
│    ├── lodash@4.17.21/      ← Already downloaded     │
│    └── ...1000+ packages    ← Accumulated over time  │
│                                                       │
│  ┌────────────────────────────────────────────┐     │
│  │          Docker Container (Sandbox)        │     │
│  │  ┌──────────────────────────────────────┐  │     │
│  │  │ /.npm  →  Points to ~/.npm          │  │     │
│  │  │           (SHARED with host!)        │  │     │
│  │  └──────────────────────────────────────┘  │     │
│  │                                             │     │
│  │  When npm runs inside:                     │     │
│  │  1. Checks /.npm cache                     │     │
│  │  2. Finds packages already there! ✅        │     │
│  │  3. No download needed                     │     │
│  │  4. Installs in seconds ⚡                  │     │
│  └────────────────────────────────────────────┘     │
│                                                       │
└──────────────────────────────────────────────────────┘

Supported Cache Directories

Vectra Guard automatically detects and mounts caches for:
EcosystemHost Cache LocationContainer MountSpeedup
npm~/.npm/.npm10.2x
Yarn v1~/.yarn/.yarn8.4x
Yarn v2+~/.yarn/cache/.yarn/cache9.1x
pnpm~/.pnpm-store/.pnpm-store12.3x
pip~/.cache/pip/.cache/pip9.6x
Poetry~/.cache/pypoetry/.cache/pypoetry8.8x
Cargo~/.cargo/.cargo15.2x
Go~/go/pkg/go/pkg11.0x
Ruby~/.gem/.gem7.3x
Maven~/.m2~/.m26.8x
Gradle~/.gradle~/.gradle7.1x
Caching is enabled by default in always mode - you get 10x speedup automatically!

Docker/Container Isolation

Vectra Guard supports multiple container runtimes:

Runtime Selection

sandbox:
  runtime: docker  # docker, podman, process (Linux only)
  image: ubuntu:22.04
  timeout: 300  # seconds
Most compatible, works everywhere
  • ✅ Works on macOS, Linux, Windows
  • ✅ Full isolation (process, network, filesystem)
  • ✅ Battle-tested and widely available
  • ⚠️ 2-5s startup overhead
# Install Docker Desktop
# macOS
brew install --cask docker

# Linux
sudo apt install docker.io
sudo systemctl enable --now docker
sudo usermod -aG docker $USER

Auto-Detection

Vectra Guard intelligently selects the best runtime:
sandbox:
  runtime: auto              # Auto-select best runtime
  auto_detect_env: true      # Detect dev vs CI
  prefer_fast: true          # Prefer fast runtimes in dev
Selection priority:
  • Dev: bubblewrap → namespace → docker
  • CI: docker → bubblewrap → namespace
  • Prod: docker → bubblewrap → namespace

Performance Comparisons

Scenario: Installing 50 packages

npm install
# 50 packages, 12.3s

Real-World Benchmarks

OperationDirectSandbox (No Cache)Sandbox (Cached)Speedup
npm install (50 pkg)12.3s12.8s1.2s10.2x
pip install (20 pkg)8.7s9.1s0.9s9.6x
cargo build45.2s46.1s4.1s11.0x
go mod download3.4s3.6s0.4s8.5x
Overhead:
  • First run: +3-5% (builds cache)
  • Cached runs: 10x FASTER than direct!
  • Trusted commands: 0% (runs on host)

Security Levels

Tune isolation without sacrificing speed:
sandbox:
  security_level: permissive
  • Full network access
  • R/W filesystem
  • 2GB memory, 2.0 CPU
  • Use for: Development

Developer Experience

Single-Line Notices

Every sandbox decision includes clear reasoning:
📦 Running in sandbox (cached).
   Why: medium risk + networked install

No Prompts Unless Needed

  • Low-risk: Silent execution
  • Medium-risk: Automatic sandboxing, no prompt
  • High-risk: Approval only if --interactive
  • Trusted: Remembered approvals skip prompts

Trust Store Integration

Approve commands once, run them on host forever:
# First time - interactive approval
vg exec --interactive "npm test"
⚠️  Command requires approval
Options:
  y  - Yes, run once
  r  - Yes, and remember (trust permanently) ← Choose this!
  n  - No, cancel
Choose: r
 Approved and remembered

# Every subsequent time
vg exec "npm test"
# → Runs immediately on HOST ⚡
# → No prompt, no sandbox, instant!

Configuration Examples

Developer Preset (Fast Development)

sandbox:
  enabled: true
  mode: auto              # Smart sandboxing
  security_level: permissive
  enable_cache: true      # 10x speedup
  network_mode: full

CI/CD Preset (Balanced)

sandbox:
  enabled: true
  mode: always           # All commands sandboxed
  security_level: strict
  enable_cache: true     # Fast CI builds
  network_mode: restricted

Production Preset (Maximum Security)

sandbox:
  enabled: true
  mode: always           # Everything sandboxed
  security_level: paranoid
  enable_cache: false    # Reproducibility
  network_mode: none

Metrics & Analytics

Track sandbox usage and performance:
vg metrics show
Example output:
Vectra Guard Sandbox Metrics
===============================
Total Executions:    1,247
  - Host:            834 (66.9%)   ← Trusted commands
  - Sandbox:         413 (33.1%)   ← Risky commands  
  - Cached:          389 (31.2%)   ← Cache hits! 🎉

Average Duration:    0.8s

By Risk Level:
  - low: 834 (66.9%)     ← Running on host
  - medium: 387 (31.0%)  ← Sandboxed but cached
  - high: 26 (2.1%)      ← Sandboxed, slower

By Runtime:
  - docker: 413

Time Saved (estimated): 4.2 hours this week! ⚡
What This Tells You:
  • 67% of commands trusted → Fast path
  • 31% cached → 10x faster
  • Only 2% truly risky → Properly isolated
  • Result: Security + Speed! 🎉

Troubleshooting

Slow Execution

sandbox:
  enable_cache: true

Docker Not Available

# Use podman instead
sandbox:
  runtime: podman

# Or process sandbox (Linux only)
sandbox:
  runtime: process

Network Issues

# Allow full network access
sandbox:
  network_mode: full

Permission Errors

# Use permissive security level
sandbox:
  security_level: permissive

# Or bind mount with write access
sandbox:
  bind_mounts:
    - host_path: /path/to/data
      container_path: /data
      read_only: false

Best Practices

Always enable caching for 10x speedup:
sandbox:
  enable_cache: true
Use auto mode for development to balance security and speed:
sandbox:
  mode: auto
Trust common commands to skip sandboxing:
vg trust add "npm test"
vg trust add "npm run build"
Monitor metrics weekly to see time saved:
vg metrics show

Next Steps

Command Protection

Learn about risk detection and guard levels

Sessions & Audit

Track and audit sandbox execution

Build docs developers (and LLMs) love