Serverless Persistence with Daytona and Modal

9 min read Module 5 of 9 Topic 14 of 25

What you'll learn

  • Explain what 'serverless persistence' means for a terminal backend
  • Configure Modal and Daytona and authenticate each correctly
  • Compare serverless backends against the always-on Docker backend from cost and latency angles
  • Choose between direct Modal and the Nous-managed gateway variant
Building this at your company? For enterprise and company teams taking this to production: book a 30-minute session with our AI engineers for architecture guidance, code review, and a rollout plan for your use case.
Book a Team Session

What “Serverless Persistence” Means Here

Lesson 13’s Docker backend gets its persistence from a single container that keeps running, sleep 2h and beyond, for the life of the Hermes process. That works, but it means you’re paying for (or at least occupying) compute even during long stretches where nobody is talking to the agent.

Daytona and Modal solve the same problem, state that survives across calls and sessions, differently: the environment hibernates when idle and wakes on demand, so you get the practical benefit of persistence (installed packages, working directory, files) without the always-on cost.

flowchart LR
    A["Tool call arrives"] --> CHECK{"Environment\nhibernating?"}
    CHECK -->|yes| WAKE["Wake environment\n(brief cold-start delay)"]
    CHECK -->|no| RUN["Already warm, run immediately"]
    WAKE --> RUN
    RUN --> IDLE["No activity for a while"]
    IDLE --> HIBERNATE["Hibernate: costs\nnearly nothing"]
    HIBERNATE -.-> CHECK

    style A fill:#EEF0F7,stroke:#6366F1,color:#0F172A
    style CHECK fill:#EEF0F7,stroke:#6366F1,color:#0F172A
    style WAKE fill:#fff7ed,stroke:#f59e0b,color:#0F172A
    style RUN fill:#f0fdf9,stroke:#0D9488,color:#0F172A
    style IDLE fill:#EEF0F7,stroke:#6366F1,color:#0F172A
    style HIBERNATE fill:#fff7ed,stroke:#f59e0b,color:#0F172A

Modal offers two integration paths: a direct connection, or routing through a Nous-managed gateway.

export MODAL_TOKEN_ID=ak-...
# or, alternatively, a ~/.modal.toml file with the same credentials
terminal:
  backend: "modal"

Validate before relying on it:

hermes doctor    # explicitly checks for MODAL_TOKEN_ID or ~/.modal.toml

Daytona

Daytona is a workspace platform purpose-built for exactly this kind of ephemeral, persistent development environment.

export DAYTONA_API_KEY=dtn_...
terminal:
  backend: "daytona"

The Daytona SDK handles server URL configuration on its own, you generally only need the API key, which keeps setup close to the simplicity of the local backend while getting Docker-equivalent statefulness with none of the always-on cost.

Comparing Your Deployment Options So Far

BackendState persists?Cost when idleCold-start delayBest for
Local (Lesson 13)Yes, on your machineN/A (your machine)NonePersonal dev work
Docker (Lesson 13)Yes, always-on containerFull compute cost, continuouslyNoneFrequent, sustained use; full control
SSH (Lesson 13)Yes, on the remote boxWhatever that box normally costsNoneKeeping execution on infra you already run
Modal / DaytonaYes, hibernates when idleNear-zero between usesBrief, on wakeBursty or infrequent use, cost-sensitive deployments

There’s no universally correct choice here, it’s a direct function of usage pattern. A bot that fields messages sporadically throughout the day (Module 6) is the textbook case for serverless persistence: you get the same continuity of state as Docker, without paying for the idle hours in between.

Common pitfall: choosing an always-on Docker backend for a low-traffic deployment out of habit, then being surprised by the compute bill. If your traffic pattern has long idle gaps, run the cost comparison before defaulting to the backend you’re most familiar with.

Exercise: if you have access to either a Modal or Daytona account, configure one as your terminal backend and run hermes doctor to confirm it authenticates correctly. Note the response latency on a request after a period of inactivity versus one immediately following, that gap is the hibernate/wake cycle in action.

Knowledge Check

3 questions to test your understanding

1 What problem does 'serverless persistence' solve that the always-on Docker backend (Lesson 13) doesn't?

2 What credential does Hermes need to use the Modal terminal backend, and how would you check it's configured correctly?

3 You're deploying a Hermes-powered messaging bot (Module 6) that gets occasional use throughout the day with long idle gaps. Which backend category from this module and the last one best fits that usage pattern, and why?

Go further with expert guidance

Ready to build production AI?
Talk to our R&D team.

These courses give you the foundation. Our embedded AI teams take you from prototype to production in 30–90 days, with your team, your codebase, your goals. Book a free strategy call to see how we can accelerate your AI initiative.

30 minutes · No obligation · Expert AI engineers, not sales reps

AI Architecture Review

Audit your current stack and identify high-impact improvements

Project Review

Get expert feedback on your AI implementation and codebase

Team Mentoring

Upskill your engineers with hands-on AI coaching sessions

AI Strategy

Define your AI roadmap, prioritization, and implementation plan