| The window opens, and a devShell that remembers what it built c20643a nandi 5d ago | 1 | """Generated stub -- the container is defined by container.toml. |
| 2 | |
| 3 | Edit container.toml, not this file. |
| 4 | """ |
| 5 | |
| 6 | import os |
| 7 | import sys |
| 8 | |
| 9 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 10 | |
| 11 | from _loader import Container # noqa: E402 |
| 12 | |
| 13 | c = Container.from_toml(__file__) |
| 14 | image, app = c.image, c.app |
| 15 | |
| 16 | |
| 17 | # No @app.function here: a Sandbox runs its command as its own process and |
| 18 | # nothing of this module is imported into it. Registering a Function would be |
| 19 | # dead weight, and its kwargs are where vm_runtime would be wrongly applied. |
| 20 | @app.local_entrypoint() |
| 21 | def main(command: str = ""): |
| 22 | c.run_sandbox(command) |
| 23 | |
| 24 | |
| 25 | @app.local_entrypoint() |
| 26 | def shell(): |
| 27 | """Leave a Sandbox running and say how to get into it. |
| 28 | |
| 29 | `modal shell --image` only takes registry references, so it cannot be |
| 30 | pointed at a published Modal image like arch-nix. Attaching to a running |
| 31 | Sandbox can, and that Sandbox is this container: same image, same volumes, |
| 32 | same resources. It outlives this process, so it also has to be killed. |
| 33 | """ |
| 34 | sb = c.open_sandbox() |
| 35 | print(f"sandbox {sb.object_id} up, with {', '.join(c.volumes) or 'no volumes'}") |
| 36 | print(f" attach: modal shell {sb.object_id} (from another terminal)") |
| 37 | print("Ctrl-C here takes it down.") |
| 38 | # Blocks on `sleep infinity`, which is the point: an ephemeral app stops |
| 39 | # when its local entrypoint returns, and stopping the app terminates the |
| 40 | # Sandbox with it -- so returning here would leave nothing to attach to. |
| 41 | try: |
| 42 | sb.wait() |
| 43 | except KeyboardInterrupt: |
| 44 | print("terminating") |
| 45 | sb.terminate() |