Skip to content

About

Small, single-file examples of Modal Sandboxes

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Modal Sandbox examples

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.

Snapshots, step by step

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 /home

Run 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.

Notes

  • -q hides Modal's progress spinner, which otherwise draws over prompts and output. It also hides sidecar logs, so sidecar_proxy.py runs without it.
  • Sidecars and proxy_traffic_via_sidecar are experimental.
  • sidecar_proxy.py sends your GitHub token (gh auth token, or GH_TOKEN) to the sidecar only.
  • The sandbox from connect_token.py stays up for 5 minutes so you can open the links in a browser.

About

Small, single-file examples of Modal Sandboxes

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages