← Back
Modal releases v1.3.4 with Directory Snapshots and 8x faster stdin writes
· releasefeatureapiperformance · modal.com ↗

New Directory Snapshots Feature

Modal has introduced Directory Snapshots, a new beta feature for persisting specific directories beyond the lifetime of individual Sandboxes. Using the new methods modal.Sandbox.snapshot_directory() and modal.Sandbox.mount_image(), developers can capture the state of a directory and later include it in a different Sandbox:

sb = modal.Sandbox.create(app=app)
snapshot = sb.snapshot_directory("/project")

sb2 = modal.Sandbox.create(app=app)
sb2.mount_image("/project", snapshot)

This feature is useful for separating the lifecycle of application code in the Sandbox's main Image from project code that changes in each session. Files in mounted snapshots benefit from optimizations that allow faster reads.

Improved Sandbox Lifecycle Management

Two new methods enhance Sandbox lifecycle control:

  • modal.Sandbox.detach(): A new recommended method to disconnect the local client from a Sandbox and clean up associated connection resources. After calling detach(), operations on the Sandbox object may fail.
  • modal.Sandbox.terminate() with wait parameter: The terminate() method now accepts an optional wait parameter. When wait=True, it blocks until the Sandbox finishes and returns the exit code, maintaining backward compatibility with the default wait=False behavior.

Performance and Convenience Improvements

  • 8x throughput increase for writing to stdin of modal.Sandbox.exec processes
  • New modal.Volume.from_id() method for referencing volumes by object ID, joining similar methods for Queue and Dict objects
  • Custom domain support for Sandboxes (requires manual setup by Modal)

These improvements streamline Sandbox management and enhance I/O performance for interactive workloads.