Skip to content

The agent that grows with you

fix(modal): persistent sandbox snapshots no longer expire after 30 days (modal 1.5.5, ttl=None) (#126740)

Teknium3f871425afe3
diff --git a/pyproject.toml b/pyproject.toml
index 6c0d1248afb..cba2f304ddb 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -256,7 +256,7 @@ kittentts = [
piper = [
"piper-tts==1.8.0; (platform_machine != 'ARM64' or sys_platform != 'win32') and (platform_machine != 'x86_64' or sys_platform != 'darwin')",
]
-modal = ["modal==1.3.4"]
+modal = ["modal==1.5.5"]
daytona = ["daytona==0.155.0"]
vercel = ["vercel==0.7.2"]
google-meet = ["playwright==1.62.0", "websockets==15.0.1"]
diff --git a/tests/tools/test_modal_snapshot_isolation.py b/tests/tools/test_modal_snapshot_isolation.py
index 0cded940d85..f17cb85c4eb 100644
--- a/tests/tools/test_modal_snapshot_isolation.py
+++ b/tests/tools/test_modal_snapshot_isolation.py
@@ -138,6 +138,7 @@ def _install_modal_test_modules(
from_id_calls: list[str] = []
registry_calls: list[tuple[str, list[str] | None]] = []
create_calls: list[dict] = []
+ snapshot_calls: list[dict] = []
class _FakeImage:
@staticmethod
@@ -157,7 +158,8 @@ def _install_modal_test_modules(
def __init__(self, image):
self.image = image
- async def _snapshot_aio():
+ async def _snapshot_aio(**kwargs):
+ snapshot_calls.append(kwargs)
return types.SimpleNamespace(object_id=snapshot_id)
async def _terminate_aio():
@@ -178,11 +180,6 @@ def _install_modal_test_modules(
raise RuntimeError(f"cannot restore {image_id}")
return _FakeSandboxInstance(image)
- class _FakeMount:
- @staticmethod
- def from_local_file(host_path: str, remote_path: str):
- return {"host_path": host_path, "remote_path": remote_path}
-
class _FakeApp:
lookup = types.SimpleNamespace(aio=_lookup_aio)
@@ -193,12 +190,12 @@ def _install_modal_test_modules(
Image=_FakeImage,
App=_FakeApp,
Sandbox=_FakeSandbox,
- Mount=_FakeMount,
)
return {
"snapshot_store": hermes_home / "modal_snapshots.json",
"create_calls": create_calls,
+ "snapshot_calls": snapshot_calls,
"from_id_calls": from_id_calls,
"registry_calls": registry_calls,
}
@@ -234,3 +231,17 @@ def test_resolve_modal_image_uses_snapshot_ids_and_registry_images(tmp_path):
assert state["from_id_calls"] == ["im-snapshot123"]
assert state["registry_calls"][0][0] == "python:3.11"
assert "ensurepip" in state["registry_calls"][0][1][0]
+
+
+def test_persistent_cleanup_snapshots_without_expiry(tmp_path, monkeypatch):
+ """The SDK default retains a filesystem snapshot for 30 days; an idle persistent
+ sandbox would then silently restart from the base image, so Hermes must opt out."""
+ state = _install_modal_test_modules(tmp_path, snapshot_id="im-fresh")
+ modal_module = _load_module("tools.environments.modal", TOOLS_DIR / "environments" / "modal.py")
+ monkeypatch.setattr(modal_module, "ensure_lazy_dep", lambda extra: None)
+
+ env = modal_module.ModalEnvironment(image="python:3.11", task_id="task-ttl")
+ env.cleanup()
+
+ assert state["snapshot_calls"] == [{"ttl": None}]
+ assert json.loads(state["snapshot_store"].read_text()) == {"direct:task-ttl": "im-fresh"}
diff --git a/tools/environments/modal.py b/tools/environments/modal.py
index 22fcb101dbc..e2d1ef97d36 100644
--- a/tools/environments/modal.py
+++ b/tools/environments/modal.py
@@ -4,7 +4,6 @@
import asyncio
import base64
import io
-import itertools
import logging
import shlex
import tarfile
@@ -152,24 +151,12 @@ class ModalEnvironment(BaseEnvironment):
logger.info("Modal: restoring from snapshot %s", restored_snapshot_id[:20])
ensure_lazy_dep("modal")
import modal as _modal
- cred_mounts = []
- try:
- from tools.credential_files import get_credential_file_mounts, iter_skills_files, iter_cache_files
- # from_iterable keeps each source lazy so a failure mid-way leaves the earlier mounts in place
- for entry in itertools.chain.from_iterable(
- fn() for fn in (get_credential_file_mounts, iter_skills_files, iter_cache_files)):
- cred_mounts.append(
- _modal.Mount.from_local_file(entry["host_path"], remote_path=entry["container_path"]))
- except Exception as e:
- logger.debug("Modal: could not load credential file mounts: %s", e)
self._worker.start()
def _create(image_spec: Any) -> None:
async def _create_sandbox():
app = await _modal.App.lookup.aio("hermes-agent", create_if_missing=True)
create_kwargs = dict(modal_sandbox_kwargs or {})
- if cred_mounts:
- create_kwargs["mounts"] = list(create_kwargs.pop("mounts", [])) + cred_mounts
sandbox = await _modal.Sandbox.create.aio(
"sleep", "infinity", image=image_spec, app=app,
timeout=int(create_kwargs.pop("timeout", 3600)), **create_kwargs)
@@ -272,7 +259,9 @@ class ModalEnvironment(BaseEnvironment):
self._sync_manager.sync_back()
if self._persistent:
async def _snapshot():
- return (await self._sandbox.snapshot_filesystem.aio()).object_id
+ # ttl=None: the SDK default (30 days) would silently expire an idle
+ # persistent sandbox's snapshot; Hermes owns its lifetime.
+ return (await self._sandbox.snapshot_filesystem.aio(ttl=None)).object_id
try:
snapshot_id = self._worker.run_coroutine(_snapshot(), timeout=60)
except Exception:
diff --git a/uv.lock b/uv.lock
index 15b66d901f9..7bd9516c896 100644
--- a/uv.lock
+++ b/uv.lock
@@ -14,108 +14,108 @@ exclude-newer = "0001-01-01T00:00:00Z" # This has no effect and is included for
exclude-newer-span = "P14D"
[options.exclude-newer-package]
-elevenlabs = false
-langfuse = "2026-09-09T16:01:26Z"
-setuptools = false
-modal = false
-pyyaml = false
-maturin = false
-numpy = false
-pvporcupine = false
-google-auth = false
+agent-client-protocol = false
aiohttp = false
-starlette = false
-mistralai = false
-firecrawl-py = false
-parallel-web = false
-markdown = false
-opentelemetry-sdk = false
-prompt-toolkit = false
-fastapi = false
+aiohttp-socks = false
+aiosqlite = false
+alibabacloud-dingtalk = false
anthropic = false
-pathspec = false
-ruff = false
-defusedxml = false
-websockets = false
-exa-py = false
-mcp = false
-python-olm = false
-wheel = false
-pytest = false
-pillow = false
-setuptools-rust = false
-tenacity = false
-sherpa-onnx-core = "2026-09-10T15:58:47Z"
-pyjwt = false
-slack-bolt = false
-fal-client = false
asyncpg = false
+azure-identity = false
boto3 = false
-ruamel-yaml = false
-sherpa-onnx = "2026-09-10T17:00:04Z"
-huggingface-hub = false
-pytest-asyncio = false
-google-cloud-pubsub = false
-slack-sdk = false
-discord-py = false
-honcho-ai = false
-faster-whisper = false
+brotlicffi = false
+browser-harness = false
certifi = false
-debugpy = false
+concurrent-log-handler = false
+croniter = false
+cryptography = false
+daytona = false
ddgs = "2026-08-26T21:52:34Z"
-packaging = false
-rich = false
-supermemory = false
-h2 = false
-unpaddedbase64 = false
-youtube-transcript-api = false
+debugpy = false
+defusedxml = false
+dingtalk-stream = false
+discord-py = false
edge-tts = false
-microsoft-teams-apps = false
-aiohttp-socks = false
-sentencepiece = false
-opentelemetry-exporter-otlp-proto-http = false
-croniter = false
-browser-harness = false
-azure-identity = false
-lark-oapi = false
+elevenlabs = false
+exa-py = false
+fal-client = false
+fastapi = false
+faster-whisper = false
+fire = false
firecrawl-anydoc = false
+firecrawl-py = false
google-api-python-client = false
-brotlicffi = false
-mem0ai = false
-qrcode = false
-soundfile = "2026-06-06T08:58:48Z"
-vercel = false
-aiosqlite = false
-tzdata = false
-python-dotenv = false
-daytona = false
-uvicorn = false
-nemo-relay = false
-requests = false
+google-auth = false
+google-auth-httplib2 = false
+google-auth-oauthlib = false
+google-cloud-pubsub = false
+h2 = false
+honcho-ai = false
httplib2 = false
httpx = false
-piper-tts = "2026-09-04T16:47:32Z"
-pyasn1 = false
-snowballstemmer = false
-concurrent-log-handler = false
-cryptography = false
-pydantic = false
-agent-client-protocol = false
-fire = false
httpx2 = false
-google-auth-oauthlib = false
-python-multipart = false
-ty = false
-openai = false
+huggingface-hub = false
+jinja2 = false
+langfuse = "2026-09-09T16:01:26Z"
+lark-oapi = false
+markdown = false
+maturin = false
mautrix = false
+mcp = false
+mem0ai = false
+microsoft-teams-apps = false
+mistralai = false
+modal = false
+nemo-relay = false
neutts = "2026-07-22T14:54:23Z"
-google-auth-httplib2 = false
+numpy = false
+openai = false
+opentelemetry-exporter-otlp-proto-http = false
+opentelemetry-sdk = false
+packaging = false
+parallel-web = false
+pathspec = false
+pillow = false
+piper-tts = "2026-09-04T16:47:32Z"
+prompt-toolkit = false
psutil = false
+pvporcupine = false
+pyasn1 = false
+pydantic = false
+pyjwt = false
+pytest = false
+pytest-asyncio = false
+python-dotenv = false
+python-multipart = false
+python-olm = false
python-telegram-bot = false
-jinja2 = false
+pyyaml = false
+qrcode = false
+requests = false
+rich = false
+ruamel-yaml = false
+ruff = false
+sentencepiece = false
+setuptools = false
+setuptools-rust = false
+sherpa-onnx = "2026-09-10T17:00:04Z"
+sherpa-onnx-core = "2026-09-10T15:58:47Z"
+slack-bolt = false
+slack-sdk = false
+snowballstemmer = false
sounddevice = false
-alibabacloud-dingtalk = false
-dingtalk-stream = false
+soundfile = "2026-06-06T08:58:48Z"
+starlette = false
+supermemory = false
+tenacity = false
+ty = false
+tzdata = false
+unpaddedbase64 = false
+uvicorn = false
+vercel = false
+websockets = false
+wheel = false
+youtube-transcript-api = false
[manifest]
overrides = [
@@ -2742,7 +2742,7 @@ requires-dist = [
{ name = "microsoft-teams-apps", marker = "extra == 'teams'", specifier = "==2.0.13.4" },
{ name = "misaki", extras = ["en"], marker = "(platform_machine != 'x86_64' and sys_platform == 'darwin' and extra == 'kittentts') or (platform_machine != 'ARM64' and sys_platform == 'win32' and extra == 'kittentts') or (sys_platform != 'darwin' and sys_platform != 'win32' and extra == 'kittentts')", git = "https://github.com/NousResearch/misaki.git?rev=f03fd2be7346952a83d3d4845c217fc7667f322d" },
{ name = "mistralai", marker = "extra == 'mistral'", specifier = "==2.4.8" },
- { name = "modal", marker = "extra == 'modal'", specifier = "==1.3.4" },
+ { name = "modal", marker = "extra == 'modal'", specifier = "==1.5.5" },
{ name = "nemo-relay", marker = "(python_full_version >= '3.14' and platform_machine == 'aarch64' and 'android' not in platform_release and sys_platform == 'linux') or (python_full_version >= '3.14' and platform_machine == 'x86_64' and 'android' not in platform_release and sys_platform == 'linux') or (python_full_version >= '3.14' and platform_machine == 'arm64' and sys_platform == 'darwin') or (python_full_version >= '3.14' and platform_machine == 'AMD64' and sys_platform == 'win32') or (python_full_version >= '3.14' and platform_machine == 'ARM64' and sys_platform == 'win32')", specifier = ">=0.8.3,<0.9" },
{ name = "neutts", extras = ["all"], marker = "python_full_version < '3.14' and extra == 'neutts'", specifier = "==1.4.1" },
{ name = "numpy", marker = "extra == 'audio-io'", specifier = "==2.4.3" },
@@ -3707,7 +3707,7 @@ wheels = [
[[package]]
name = "modal"
-version = "1.3.4"
+version = "1.5.5"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "aiohttp" },
@@ -3719,15 +3719,14 @@ dependencies = [
{ name = "rich" },
{ name = "synchronicity" },
{ name = "toml" },
- { name = "typer" },
{ name = "types-certifi" },
{ name = "types-toml" },
{ name = "typing-extensions" },
{ name = "watchfiles" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/d6/06/2ec6ebed7e82b45ba386bf8df71e41aa13b6b18253bb6a49dc77a92cbac1/modal-1.3.4.tar.gz", hash = "sha256:9cc7815a57a4f0b62d4027da1a5526a2345af0643fd3354b32977480a87fcff5", size = 674717, upload-time = "2026-02-23T15:44:05.334Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/b9/a5/9e322043716e511b7f6c9120804f33b92e21a818bf4709b2d98b3c76d665/modal-1.5.5.tar.gz", hash = "sha256:30df363ed1898cc3d91a09ff3f95c38ab043f6b6294011b01085312c6a0ac777", size = 870356, upload-time = "2026-08-28T19:51:34.881Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/2c/aa/f0ffbe6bf679a597e8be692ca3cde47de6156435c2b72cf752fec719bb1f/modal-1.3.4-py3-none-any.whl", hash = "sha256:d66a851969f447936b3512f1c3708435ce1ca81171eeddc3eb0678f594493380", size = 773837, upload-time = "2026-02-23T15:44:03.635Z" },
+ { url = "https://files.pythonhosted.org/packages/04/19/b3dca8baec119126058b12ca620e44022e4d08a091956668bd04180c89a7/modal-1.5.5-py3-none-any.whl", hash = "sha256:8d10d3ee09818aaba1973b73ce2521ab8961b63a29b5b52e3ff0d25e7a74808e", size = 985163, upload-time = "2026-08-28T19:51:32.404Z" },
]
[[package]]
@@ -6538,14 +6537,14 @@ wheels = [
[[package]]
name = "synchronicity"
-version = "0.11.1"
+version = "0.12.5"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "typing-extensions" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/a3/26/8874d34755691994266d4a844ba8d53d10c2690ec67f246ca4d6b6f34cbb/synchronicity-0.11.1.tar.gz", hash = "sha256:3628df9ab34bd7be89b729104114841c62612c5d5ec43b76f4b7b243185ec1a8", size = 58131, upload-time = "2025-12-19T18:28:42.291Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/5d/1c/f51dc54bbd302991026a53f9790735540e0e9e1184e9d5939f02446aa5bc/synchronicity-0.12.5.tar.gz", hash = "sha256:94d96b1d85698e3056b96a793b8c0949af6584e4a7d877fabdeb5385efe230aa", size = 60745, upload-time = "2026-06-18T21:06:23.545Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/3f/b9/71153db12f4ad029cfe9b7fbf9792ef3fc9ade4485d31a13470b52954e62/synchronicity-0.11.1-py3-none-any.whl", hash = "sha256:53959c7f8b9b852fb5ea4d3d290a47a04310ede483a4cf0f8452cb4b5fa09db2", size = 40399, upload-time = "2025-12-19T18:28:40.972Z" },
+ { url = "https://files.pythonhosted.org/packages/06/74/ad9b99520f70c0bc3318e582e359d360cfc0f7afd7bf368a7f24013cece7/synchronicity-0.12.5-py3-none-any.whl", hash = "sha256:fdbbb10d437bc08a6b0f814fc66fddd1b58ffed314533d42f1ab555801e781af", size = 41107, upload-time = "2026-06-18T21:06:22.505Z" },
]
[[package]]
diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.md
index b8fce780eba..54f07356258 100644
--- a/website/docs/user-guide/configuration.md
+++ b/website/docs/user-guide/configuration.md
@@ -515,7 +515,7 @@ terminal:
**Required:** Either `MODAL_TOKEN_ID` + `MODAL_TOKEN_SECRET` environment variables, or a `~/.modal.toml` config file.
-**Persistence:** When enabled, the sandbox filesystem is snapshotted on cleanup and restored on next session. Snapshots are tracked in `~/.hermes/modal_snapshots.json`. This preserves filesystem state, not live processes, PID space, or background jobs.
+**Persistence:** When enabled, the sandbox filesystem is snapshotted on cleanup and restored on next session. Snapshots are tracked in `~/.hermes/modal_snapshots.json` and are retained until you delete them (Hermes opts out of the Modal SDK's 30-day snapshot expiry). This preserves filesystem state, not live processes, PID space, or background jobs.
**Credential files:** Automatically mounted from `~/.hermes/` (OAuth tokens, etc.) and synced before each command.