{
 "kind": "api",
 "slug": "modal-sandboxes",
 "path": "apis/modal-sandboxes/",
 "name": "Modal Sandboxes",
 "logo": "https://agentgid.com/media/avatars/modal-labs.png",
 "maker": "Modal Labs",
 "density": "full",
 "crumbs": [
  [
   "APIs",
   "apis/"
  ],
  [
   "Code sandboxes",
   "apis/sandbox/"
  ]
 ],
 "lead": "Safe cloud boxes to run untrusted code.",
 "chips": [
  {
   "label": "Code sandboxes",
   "path": "apis/sandbox/"
  }
 ],
 "primary": {
  "label": "Copy prompt for your agent",
  "copy": "Run AI-generated code in a Modal Sandbox with modal 1.6.3: read MODAL_TOKEN_ID and MODAL_TOKEN_SECRET from the server environment, create the sandbox with block_network=True, a timeout and a memory limit, and never pass my secrets into it."
 },
 "links": [
  {
   "label": "Website",
   "href": "https://modal.com"
  },
  {
   "label": "Pricing",
   "href": "https://modal.com/pricing"
  },
  {
   "label": "GitHub",
   "href": "https://github.com/modal-labs/modal-client"
  }
 ],
 "track": "Outages, price changes and new versions on your dashboard",
 "verdicts": [
  {
   "key": "price",
   "label": "Price",
   "value": "Free every month",
   "status": "yes",
   "sub": "Then from $250/mo",
   "quote": null,
   "note": "Free tier: Starter: $30/month of free compute, no monthly fee. As reported on the official pricing page, checked Nov 1, 2026.",
   "src": "https://modal.com/pricing"
  },
  {
   "key": "commercial",
   "label": "Commercial use",
   "value": "With conditions",
   "status": "cond",
   "sub": null,
   "quote": "rent, resell or otherwise allow any third party direct access to or use of the Service",
   "note": "You may run your users' or agents' code through your own product, but not rent, resell or give third parties direct access to Modal, and not process prohibited content. Data: Not stated as allowed; the terms give Modal a license to customer data only as needed to provide the service.",
   "src": "https://modal.com/legal/terms"
  },
  {
   "key": "key",
   "label": "Key & sign-up",
   "value": "API key, server only",
   "status": "info",
   "sub": "Env var MODAL_TOKEN_ID and MODAL_TOKEN_SECRET (or ~/.modal.toml written by modal token set)",
   "quote": "Modal API tokens use MODAL_TOKEN_ID and MODAL_TOKEN_SECRET.",
   "note": "A Modal API token pair (token ID and token secret), created with modal setup in a browser or in the workspace settings.",
   "src": "https://modal.com/docs/sdk/py/latest/config.md"
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Community MCP server",
   "status": "cond",
   "sub": "llms.txt · SDK",
   "quote": null,
   "note": " Our agent check: 4 of 6 (Nov 13, 2026).",
   "src": "https://modal.com/llms.txt"
  }
 ],
 "vfoot": "Checked against the maker's official pages, pricing on Nov 1, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What Modal Sandboxes does",
   "parts": [
    {
     "t": "prose",
     "text": "Modal Sandboxes are short-lived, locked-down computers in the cloud where your app runs code it does not trust, such as code written by an AI assistant or uploaded by users. If that code breaks something, only the sandbox is affected. You pay per second for the processor and memory it actually uses."
    },
    {
     "t": "list",
     "items": [
      "Modal Sandboxes is one of 12 APIs in the Code sandboxes category on AgentGid.",
      "Its cheapest paid plan ($250 a month) is the 7th cheapest of the 9 here with a monthly plan.",
      "It is one of 11 that can be started for free.",
      "4 of them ship an official MCP server; Modal Sandboxes does not.",
      "Its official SDK is the 1st most downloaded in the category (12.7M a week)."
     ],
     "muted": true
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Run code your AI assistant wrote",
       "text": "Let a chatbot or coding agent run the Python it just wrote and read the result, without risking your own server.",
       "idea": false
      },
      {
       "title": "Run code your users submit",
       "text": "Run homework, coding-challenge answers or user plugins in a box with no internet and a time limit, so a bad script cannot leak data or run forever.",
       "idea": false
      },
      {
       "title": "Hand files in and out",
       "text": "Upload a spreadsheet or a project into the sandbox, let the code work on it, and read the results back.",
       "idea": false
      },
      {
       "title": "Live preview of an app an agent built",
       "text": "Start a small web server inside the sandbox and open it through a private link, so you can try what the agent made.",
       "idea": false
      },
      {
       "title": "Save a ready setup and reuse it",
       "text": "Install the tools once, save the sandbox's state, and start every new session from that saved copy so it begins faster.",
       "idea": false
      },
      {
       "title": "Grade many AI attempts at once",
       "text": "Run hundreds of copies of the same task side by side to test or score an AI model's answers, each in its own clean box.",
       "idea": true
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "Modal Sandboxes popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "12M",
       "l": "SDK downloads a week",
       "d": "+8.1% on the 4-week average",
       "up": true
      },
      {
       "n": "24",
       "l": "public agent repos use its SDK"
      },
      {
       "n": "539",
       "l": "GitHub stars, modal-labs/modal-client"
      }
     ]
    },
    {
     "t": "small",
     "text": "SDK downloads from npm and PyPI, weekly. Numbers as of Nov 17, 2026."
    }
   ]
  },
  {
   "id": "pricing",
   "nav": "Pricing and limits",
   "h2": "Pricing",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "Free tier",
       "v": "Starter: $30/month of free compute, no monthly fee"
      },
      {
       "l": "Cheapest plan",
       "v": "$250 a month"
      },
      {
       "l": "Usage price",
       "v": "Sandbox CPU $0.00003942 per physical core (2 vCPU) per second; memory $0.00000667 per GiB per second"
      },
      {
       "l": "Plans",
       "v": "Minimum 0.125 cores per container. Team plan $250/month + compute includes $100/month credits. Since 2026-09-01, Shared Endpoint tokens are billed from the first request even on Starter. No vendor MCP server found; third-party ones exist."
      }
     ]
    },
    {
     "t": "h3",
     "text": "What one action costs"
    },
    {
     "t": "table",
     "head": [
      "Action",
      "Price"
     ],
     "num": true,
     "rows": [
      [
       "1 physical CPU core (2 vCPU) for 1 second in a sandbox",
       "$0.00003942"
      ],
      [
       "1 GiB of memory for 1 second in a sandbox",
       "$0.00000667"
      ],
      [
       "Team plan for a month (plus compute; includes $100 of credits)",
       "$250"
      ]
     ]
    },
    {
     "t": "more",
     "items": [
      {
       "title": "Price history",
       "items": [
        "A year of the pricing page in the Internet Archive (14 months): the lowest monthly figure went from $30 (2025-10) to $30 (2026-11)."
       ]
      }
     ]
    },
    {
     "t": "small",
     "text": "As reported on the official pricing page, checked Nov 1, 2026. Prices change: confirm before you buy.",
     "link": "modal.com/pricing",
     "href": "https://modal.com/pricing"
    }
   ]
  },
  {
   "id": "limits",
   "nav": null,
   "spy_as": "pricing",
   "h2": "Limits",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "All plans",
       "v": "A sandbox lives 5 minutes by default and at most 24 hours",
       "src": "https://modal.com/docs/guide/sandboxes.md"
      },
      {
       "l": "Starter",
       "v": "100 containers and 10 GPUs at the same time, 3 seats",
       "src": "https://modal.com/pricing"
      },
      {
       "l": "Team",
       "v": "5,000 containers and 50 GPUs at the same time",
       "src": "https://modal.com/pricing"
      },
      {
       "l": "All plans",
       "v": "At least 0.125 CPU cores and 128 MiB of memory are billed per sandbox",
       "src": "https://modal.com/docs/guide/sandbox-resources.md"
      },
      {
       "l": "Starter / Team",
       "v": "Logs are kept 1 day on Starter and 30 days on Team",
       "src": "https://modal.com/pricing"
      }
     ]
    },
    {
     "t": "small",
     "text": "From the official docs.",
     "link": "modal.com/docs/guide/sandboxes.md",
     "href": "https://modal.com/docs/guide/sandboxes.md"
    }
   ]
  },
  {
   "id": "access",
   "nav": "Access and terms",
   "h2": "Key and access",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "How it signs in",
       "v": "A Modal API token pair (token ID and token secret), created with modal setup in a browser or in the workspace settings."
      },
      {
       "l": "Environment variable",
       "v": "MODAL_TOKEN_ID and MODAL_TOKEN_SECRET (or ~/.modal.toml written by modal token set)",
       "code": true
      },
      {
       "l": "Safe in browser code",
       "v": "No, keep it on your server",
       "status": "no"
      },
      {
       "l": "Card at sign-up",
       "v": "Not stated on the pages we read"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Steps only a person can do"
    },
    {
     "t": "list",
     "items": [
      "Sign up for Modal and connect the machine with modal setup (opens a browser), or create a token in the workspace settings. Put MODAL_TOKEN_ID and MODAL_TOKEN_SECRET in the server environment (kept out of git) for the modal package to read.",
      "Set a workspace budget so runaway sandboxes cannot run up a large bill. No code change; also set timeout and resource limits on every Sandbox.create.",
      "Decide whether to install Modal's agent skill or the standalone command-line tool from its install script. If yes, the person runs it; the agent uses pip install modal at a pinned version inside the project's virtual environment."
     ]
    }
   ]
  },
  {
   "id": "terms",
   "nav": null,
   "spy_as": "access",
   "h2": "Commercial use and your data",
   "parts": [
    {
     "t": "prose",
     "text": "Modal is a paid online service with free monthly credits; its client libraries are open source under Apache-2.0. You may run your users' code through your product, but not resell or give others direct access to Modal."
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In a paid app",
       "v": "With conditions",
       "status": "cond",
       "sub": "You may run your users' or agents' code through your own product, but not rent, resell or give third parties direct access to Modal, and not process prohibited content.",
       "quote": "rent, resell or otherwise allow any third party direct access to or use of the Service",
       "src": "https://modal.com/legal/terms"
      },
      {
       "l": "inside-app-bundle",
       "v": "Yes",
       "status": "yes",
       "sub": "The modal client packages (Python and JavaScript) are Apache-2.0; keep the license notice when you ship them.",
       "quote": "\"license\":\"Apache-2.0\"",
       "src": "https://registry.npmjs.org/modal/0.11.1"
      },
      {
       "l": "Trains on what you send",
       "v": "Not stated as allowed; the terms give Modal a license to customer data only as needed to provide the service.",
       "quote": null,
       "src": null
      },
      {
       "l": "Keeps your data",
       "v": "Sandbox logs are kept 1 day on Starter and 30 days on Team; sandbox memory snapshots 7 days; filesystem snapshots 30 days by default.",
       "quote": null,
       "src": null
      },
      {
       "l": "Where data is stored",
       "v": "Requests are routed through us-east (Virginia) by default; choosing a container region costs 1.15 to 1.75 times the base price.",
       "quote": null,
       "src": null
      }
     ]
    }
   ]
  },
  {
   "id": "errors",
   "nav": null,
   "spy_as": "access",
   "h2": "Errors to handle",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "modal.exception.AuthError",
       "v": "The token is missing or invalid.",
       "sub": "Set MODAL_TOKEN_ID and MODAL_TOKEN_SECRET (or run modal token info to check the saved token)."
      },
      {
       "l": "modal.exception.SandboxTimeoutError",
       "v": "The sandbox ran past its timeout (5 minutes unless you set one).",
       "sub": "Pass a longer timeout to Sandbox.create (up to 24 hours) or split the work."
      },
      {
       "l": "modal.exception.ExecTimeoutError",
       "v": "One command run with exec took longer than its own timeout.",
       "sub": "Raise the timeout on sb.exec, or stop the command and report it to the user."
      },
      {
       "l": "modal.exception.ResourceExhaustedError",
       "v": "A quota or rate limit was hit, for example too many containers at once for your plan.",
       "sub": "Retry later with backoff, run fewer sandboxes at once, or move to a plan with higher limits."
      },
      {
       "l": "exit code 137",
       "v": "The sandbox or process was killed (terminated, or out of memory).",
       "sub": "Check sb.returncode and the dashboard's exit reason; raise the memory request if it ran out of memory."
      }
     ]
    }
   ]
  },
  {
   "id": "agent",
   "nav": "For agents",
   "h2": "Use it from an agent",
   "parts": [
    {
     "t": "rows",
     "rows": [
      {
       "l": "Our agent check",
       "v": "4 of 6: llms.txt yes, OpenAPI no, SDK yes, MCP no, status page yes, AI assistants allowed yes",
       "sub": "Checked Nov 13, 2026."
      },
      {
       "l": "MCP server",
       "v": "Community servers only",
       "sub": null
      },
      {
       "l": "npm",
       "v": "npm install modal",
       "code": true
      },
      {
       "l": "PyPI",
       "v": "pip install modal",
       "code": true
      }
     ]
    },
    {
     "t": "h3",
     "text": "Instructions in its docs to check first"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "The docs say",
       "v": "“Read https://modal.com/docs/guide/getting-started.md and walk me through Modal setup.”",
       "sub": "A ready prompt for coding agents; the setup needs a Modal account and a browser sign-in, which only the person can do."
      },
      {
       "l": "The docs say",
       "v": "“modal skills install # [--claude] [--global]”",
       "sub": "Ask the person first; with --global it installs an agent skill for every project on the machine."
      },
      {
       "l": "The docs say",
       "v": "“curl -LsSf uvx.sh/modal/install.sh | sh”",
       "sub": "Ask the person first; it runs a downloaded install script. Prefer pip install modal at a pinned version in the project's virtual environment."
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "Modal Sandboxes",
       "me": true,
       "facts": [
        "from $0.00000667 per GiB per",
        "Free tier"
       ]
      },
      {
       "name": "E2B",
       "why": "Pick E2B for sandboxes built only for AI agents, on small virtual machines that start in under a second.",
       "path": "apis/e2b/",
       "facts": [
        "Free (open source)",
        "Free tier",
        "Official MCP"
       ]
      },
      {
       "name": "Vercel Sandbox",
       "why": "Pick Vercel Sandbox when your app already runs on Vercel and you want short-lived Linux machines next to it.",
       "path": "apis/vercel-sandbox/",
       "facts": [
        "from $0.0212 per GB-hour",
        "Free tier",
        "Official MCP"
       ]
      },
      {
       "name": "Daytona",
       "why": "Pick Daytona when you need fast-starting sandboxes with Windows or GPU options, billed per second.",
       "path": "apis/daytona/",
       "facts": [
        "from $0.000108 per GiB-hour after",
        "Free tier",
        "Official MCP"
       ]
      }
     ],
     "more": "All code sandboxes APIs",
     "more_path": "apis/sandbox/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "Run AI-generated code in a Modal Sandbox with modal 1.6.3: read MODAL_TOKEN_ID and MODAL_TOKEN_SECRET from the server environment, create the sandbox with block_network=True, a timeout and a memory limit, and never pass my secrets into it."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Create a Modal account (an account is required), then install the Python package.",
       "code": "pip install modal",
       "src": "https://modal.com/docs/guide/getting-started.md"
      },
      {
       "text": "Connect your computer to your account; this opens a browser to sign in and saves a token.",
       "code": "modal setup",
       "src": "https://modal.com/docs/guide/getting-started.md"
      },
      {
       "text": "Create a sandbox, run a command in it and read the output.",
       "code": "sb_app = modal.App.lookup(\"my-app\", create_if_missing=True)\nsb = modal.Sandbox.create(app=sb_app)\n\np = sb.exec(\"python\", \"-c\", \"print('hello')\", timeout=3)\nprint(p.stdout.read())\n",
       "src": "https://modal.com/docs/guide/sandboxes.md"
      }
     ]
    },
    {
     "t": "h3",
     "text": "First request"
    },
    {
     "t": "tabs",
     "label": "First request",
     "items": [
      {
       "tab": "Request",
       "code": "sb = modal.Sandbox.create(app=sb_app)\n\n# Read returncode of individual process\np = sb.exec(\"sh\", \"-c\", \"exit 42\")\np.wait()\nprint(p.returncode) # 42\n\n# Read returncode of finished sandbox\n# Terminate sends a SIGKILL, code 137\nsb.terminate(wait=True)\nprint(sb.returncode) # 137\n",
       "intro": "sb_app comes from modal.App.lookup(\"my-app\", create_if_missing=True), as in the first example of the guide."
      },
      {
       "tab": "Response",
       "code": "42\n137\n"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "Leaving the default network open for code written by an AI or a user.",
       "fix": "Create the sandbox with block_network=True, or allow only the needed sites with outbound_domain_allowlist.",
       "why": "By default sandboxes can reach any public address, so bad code could send data out."
      },
      {
       "dont": "Passing your API keys or Modal secrets into the sandbox that runs untrusted code.",
       "fix": "Keep secrets on your server and give the sandbox only the files it needs.",
       "why": "Modal's shared responsibility model puts keeping credentials out of untrusted workloads on you."
      },
      {
       "dont": "Setting large cpu and memory requests \"to be safe\".",
       "fix": "Leave them unset (bursting covers most loads) and set limits to cap runaway code.",
       "why": "Requested resources are billed for the sandbox's whole life, even when idle."
      },
      {
       "dont": "Expecting a sandbox to keep running for a long agent session without a timeout.",
       "fix": "Pass timeout= (up to 24 hours) and an idle_timeout, and snapshot state you want to keep.",
       "why": "The default lifetime is 5 minutes."
      },
      {
       "dont": "Catching the built-in TimeoutError around a readiness probe.",
       "fix": "Catch modal.exception.TimeoutError.",
       "why": "Modal raises its own error class, which a bare except TimeoutError does not catch."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Is there a free plan?",
       "a": "Yes, the Starter plan has no monthly fee and includes $30 of compute a month; you pay only above that.",
       "evidence": {
        "url": "https://modal.com/pricing",
        "quote": "starter has no monthly fee and includes $30 of compute (gpus, cpus, memory) per month."
       }
      },
      {
       "q": "Can code in the sandbox reach my other Modal resources or the internet?",
       "a": "It cannot reach your Modal resources or accept incoming connections by default, but it can reach the internet unless you block or limit it.",
       "evidence": {
        "url": "https://modal.com/docs/guide/sandbox-networking.md",
        "quote": "Sandboxes are built to be secure-by-default, meaning that a default Sandbox has no ability to accept incoming network connections or access your Modal resources."
       }
      },
      {
       "q": "Can I use it from JavaScript?",
       "a": "Yes, the modal package on npm runs sandboxes from server-side Node.js 22+, Deno or Bun.",
       "evidence": {
        "url": "https://modal.com/docs/sdk/js/latest.md",
        "quote": "It works in server-side Node.js (Node 22+), Deno, and Bun projects."
       }
      },
      {
       "q": "How do I keep costs down?",
       "a": "Do not set a resource request unless you need guaranteed capacity; you then pay only for what the sandbox uses, and you can set a workspace budget.",
       "evidence": {
        "url": "https://modal.com/docs/guide/sandbox-resources.md",
        "quote": "Not setting a resource request means you only pay for the resources your Sandbox is actively using each second, with the small default request as the minimum."
       }
      },
      {
       "q": "Do sandboxes get GPUs?",
       "a": "Yes, with the gVisor runtime; GPU sandboxes can be interrupted, unlike CPU ones.",
       "evidence": {
        "url": "https://modal.com/docs/guide/sandbox-resources.md",
        "quote": "Unlike CPU Sandboxes, GPU Sandboxes are subject to preemption."
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Maker",
   "Modal Labs"
  ],
  [
   "Category",
   "Code sandboxes"
  ],
  [
   "Price",
   "from $0.00000667 per GiB per"
  ],
  [
   "Plans from",
   "$250/mo"
  ],
  [
   "Official SDK",
   "npm modal, PyPI modal"
  ],
  [
   "Latest SDK",
   "1.6.3 on npm"
  ],
  [
   "Agent check",
   "4 of 6"
  ],
  [
   "Pricing checked",
   "Nov 1, 2026"
  ]
 ],
 "good": [
  "You need a Modal account and a token. The free Starter plan includes $30 of compute each month.",
  "Sandboxes cost about three times the normal processor and memory price, because they are never interrupted.",
  "By default code in a sandbox can reach any site on the internet; block it or allow only the sites it needs."
 ],
 "checked_line": "Read by AgentGid from 25 official pages, card checked Nov 10, 2026; usage numbers update daily."
}