Cette page est affichée en anglais. Une traduction française est en cours.
WorkflowsMay 7, 2026·3 min de lecture

Modal Sandboxes — Secure Cloud Code Execution for AI Agents

Modal Sandboxes spin up secure Linux environments for agent-generated code in seconds. Custom images, GPUs, persistent volumes from any Modal Function.

Modal
Modal · Community
Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : New
Point d'entrée
Asset
Commande CLI universelle
npx tokrepo install fad6cf5b-d22c-4802-9762-ca47112a05ff
Introduction

Modal Sandboxes are isolated Linux environments you spin up programmatically — perfect for running agent-generated code, fine-tuning, or untrusted user code. Custom Docker-style images, optional GPUs, persistent volumes, sub-second cold start. Best for: AI agents that need to execute generated Python / shell / Node code safely. Works with: Modal SDK (Python). Setup time: 5 minutes.


Spawn a sandbox

import modal

app = modal.App("agent-sandbox")
image = modal.Image.debian_slim(python_version="3.12").pip_install("pandas", "numpy", "matplotlib")

@app.function(image=image)
def run_agent_code(code: str):
    sb = modal.Sandbox.create(
        image=image,
        cpu=2.0,
        memory=4096,
        timeout=300,
        app=app,
    )

    process = sb.exec("python", "-c", code)
    stdout = process.stdout.read()
    stderr = process.stderr.read()
    sb.terminate()

    return {"stdout": stdout, "stderr": stderr, "exit_code": process.returncode}

Sandbox with persistent storage

volume = modal.Volume.from_name("agent-workspace", create_if_missing=True)

sb = modal.Sandbox.create(
    image=image,
    volumes={"/workspace": volume},
    workdir="/workspace",
)

# Files written to /workspace persist across sandboxes
sb.exec("python", "fetch_data.py")
volume.commit()

# Later sandbox reads the same files
sb2 = modal.Sandbox.create(volumes={"/workspace": volume})
sb2.exec("python", "process_data.py")

GPU sandbox

sb = modal.Sandbox.create(
    image=image,
    gpu="A10G",  # or "H100", "T4", etc
    timeout=3600,
)
sb.exec("python", "train.py")

Why use Modal Sandboxes vs Docker locally

  • Spin up in <1s vs Docker's tens of seconds
  • Pre-built images cached at the platform level
  • Pay per second of execution
  • Same SDK works for Functions, Sandboxes, Volumes, GPUs
  • Built-in monitoring, logs, dashboards

FAQ

Q: Is Modal free? A: Modal has a free tier ($30/mo platform credit). Beyond that you pay per second of compute (CPU + memory + GPU). No platform fee — just resources used.

Q: How is this different from E2B? A: E2B and Modal Sandboxes overlap heavily. E2B optimizes for sandbox-as-a-product (the fastest cold start, isolated networking by default). Modal optimizes for the bigger Modal platform (Functions, Volumes, queues, GPUs). Both work for agent code execution; pick by ecosystem fit.

Q: Can I install custom packages in the sandbox? A: Yes — define an image with modal.Image.debian_slim().pip_install(...) or apt_install(...) or dockerfile_commands(...). The image is built once and cached for fast cold starts.


Quick Use

  1. pip install modal && modal token new
  2. Define an image with modal.Image.debian_slim().pip_install(...)
  3. Spawn modal.Sandbox.create(image=...) and call sb.exec(...)

Intro

Modal Sandboxes are isolated Linux environments you spin up programmatically — perfect for running agent-generated code, fine-tuning, or untrusted user code. Custom Docker-style images, optional GPUs, persistent volumes, sub-second cold start. Best for: AI agents that need to execute generated Python / shell / Node code safely. Works with: Modal SDK (Python). Setup time: 5 minutes.


Spawn a sandbox

import modal

app = modal.App("agent-sandbox")
image = modal.Image.debian_slim(python_version="3.12").pip_install("pandas", "numpy", "matplotlib")

@app.function(image=image)
def run_agent_code(code: str):
    sb = modal.Sandbox.create(
        image=image,
        cpu=2.0,
        memory=4096,
        timeout=300,
        app=app,
    )

    process = sb.exec("python", "-c", code)
    stdout = process.stdout.read()
    stderr = process.stderr.read()
    sb.terminate()

    return {"stdout": stdout, "stderr": stderr, "exit_code": process.returncode}

Sandbox with persistent storage

volume = modal.Volume.from_name("agent-workspace", create_if_missing=True)

sb = modal.Sandbox.create(
    image=image,
    volumes={"/workspace": volume},
    workdir="/workspace",
)

# Files written to /workspace persist across sandboxes
sb.exec("python", "fetch_data.py")
volume.commit()

# Later sandbox reads the same files
sb2 = modal.Sandbox.create(volumes={"/workspace": volume})
sb2.exec("python", "process_data.py")

GPU sandbox

sb = modal.Sandbox.create(
    image=image,
    gpu="A10G",  # or "H100", "T4", etc
    timeout=3600,
)
sb.exec("python", "train.py")

Why use Modal Sandboxes vs Docker locally

  • Spin up in <1s vs Docker's tens of seconds
  • Pre-built images cached at the platform level
  • Pay per second of execution
  • Same SDK works for Functions, Sandboxes, Volumes, GPUs
  • Built-in monitoring, logs, dashboards

FAQ

Q: Is Modal free? A: Modal has a free tier ($30/mo platform credit). Beyond that you pay per second of compute (CPU + memory + GPU). No platform fee — just resources used.

Q: How is this different from E2B? A: E2B and Modal Sandboxes overlap heavily. E2B optimizes for sandbox-as-a-product (the fastest cold start, isolated networking by default). Modal optimizes for the bigger Modal platform (Functions, Volumes, queues, GPUs). Both work for agent code execution; pick by ecosystem fit.

Q: Can I install custom packages in the sandbox? A: Yes — define an image with modal.Image.debian_slim().pip_install(...) or apt_install(...) or dockerfile_commands(...). The image is built once and cached for fast cold starts.


Source & Thanks

Built by Modal. Commercial product with free tier.

modal.com/docs — Sandbox documentation

🙏

Source et remerciements

Built by Modal. Commercial product with free tier.

modal.com/docs — Sandbox documentation

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires