Small, single-file examples of Modal Sandboxes.
pip install modal
modal setup| Example | What it shows | Run |
|---|---|---|
create_many.py |
Start 1,000 sandboxes at once | modal run create_many.py |
snapshot_fs.py |
A shared filesystem snapshot as the base, with a per-user directory snapshot mounted on top | see below |
sidecar_proxy.py |
gh in a sandbox that only has a placeholder token. All HTTPS goes through a sidecar that adds the real token and allows only GETs to api.github.com |
modal run sidecar_proxy.py |
connect_token.py |
Authenticated requests into a network-locked sandbox, with the caller's identity | modal run -q connect_token.py |
inject_token.py is the mitmproxy script the sidecar runs. whoami.py is the server in the connect-token sandbox.
Each command asks you to edit a file, then snapshots it.
modal run -q snapshot_fs.py::shared # edit the shared file, snapshot the filesystem
modal run -q snapshot_fs.py::user --user user1 # edit user1's file, snapshot /home
modal run -q snapshot_fs.py::user --user user2
modal run -q snapshot_fs.py::show --user user1 # base snapshot + user1's /homeRun shared again and both users see the new shared file, each with their own /home.
Snapshot ids are kept in snapshot_fs.json. Delete it to start over.
-qhides Modal's progress spinner, which otherwise draws over prompts and output. It also hides sidecar logs, sosidecar_proxy.pyruns without it.- Sidecars and
proxy_traffic_via_sidecarare experimental. sidecar_proxy.pysends your GitHub token (gh auth token, orGH_TOKEN) to the sidecar only.- The sandbox from
connect_token.pystays up for 5 minutes so you can open the links in a browser.