GEMINI LABJP
VIDEO — Agentic video understanding reached 3.7 Flash, 3.6 Flash, and 3.5 Flash-Lite on September 1. The model navigates the timeline itself rather than sampling frames at a fixed rateTOKENS — Because it pulls transcripts, frames, or audio only when it needs them, Google measures up to 88% fewer tokens on long-form contentSCOPE — It works across both the Interactions and GenerateContent APIs. If you have costed out long-video work before, the assumptions have movedMUSIC — Lyria 3.5 entered public preview on September 3, generating full-length songs at 44.1 kHz stereoCONTROL — Lyria 3.5 accepts text and image inputs, with better musical coherence, more natural vocals, and finer control over duration and structureROBOTICS — gemini-robotics-er-2-streaming-preview is tuned for real-time streaming over the Live API, with function calling that blocks on physical robot actionsVIDEO — Agentic video understanding reached 3.7 Flash, 3.6 Flash, and 3.5 Flash-Lite on September 1. The model navigates the timeline itself rather than sampling frames at a fixed rateTOKENS — Because it pulls transcripts, frames, or audio only when it needs them, Google measures up to 88% fewer tokens on long-form contentSCOPE — It works across both the Interactions and GenerateContent APIs. If you have costed out long-video work before, the assumptions have movedMUSIC — Lyria 3.5 entered public preview on September 3, generating full-length songs at 44.1 kHz stereoCONTROL — Lyria 3.5 accepts text and image inputs, with better musical coherence, more natural vocals, and finer control over duration and structureROBOTICS — gemini-robotics-er-2-streaming-preview is tuned for real-time streaming over the Live API, with function calling that blocks on physical robot actions
Articles/API / SDK
API / SDK/2026-07-18Advanced

Keeping a Long-Running Managed Agent Alive Across Sandbox Recycling — Durable Checkpoints and Idempotent Resume

A Managed Agents sandbox can be recycled out from under you. Before 40 minutes of work resets to zero, we design a durable checkpoint that pushes progress outside the sandbox and an idempotent resume that never runs a side effect twice. With working SQLite code.

Gemini API234Managed Agents8Architecture10Idempotency3Operations12

Premium Article

One morning I opened the run log and my hand stopped over the trackpad.

The aggregation agent I had kicked off the night before had vanished 42 minutes in. Not an error. The run had simply ended partway through, and by morning a different sandbox was trying to start it over from step one.

Managed Agents spins up a Google-hosted, isolated Linux sandbox in a single API call and runs your agent autonomously inside it. For a solo developer with no servers of their own, that lightness is a gift. But lightness has an underside: the sandbox is not mine. Idle timeouts, platform maintenance, capacity reallocation. The runtime gets quietly rebuilt on a schedule that has nothing to do with my convenience.

What I had kept in inventory was progress that lived only inside the sandbox. Forty-two minutes of intermediate results disappeared when the environment did. Back to square one.

This article is about erasing that square one. A durable checkpoint that pushes progress outside the sandbox, and an idempotent resume that won't run a side effect twice. We'll build it up in order, all the way down to code you can run.

Why a Managed Agent disappears mid-run

Let's set the premise straight. Vanishing isn't an anomaly — it's a property that lives on the platform side.

A Managed Agents sandbox is, by design, largely ephemeral. It comes up for a single run and gets cleaned up when the run ends. Even mid-run, the environment can be rebuilt for reasons like these.

TriggerWhat happensHow it looks to you
Idle timeoutReclaimed after inactivity during an external wait (API response, etc.)The run disappears after a long wait
Maintenance / reallocationThe host moves the sandbox to another nodeNon-reproducible interruption; the reason rarely lands in your logs
Wall-clock ceilingYou hit the runtime boundary for a single runIt cuts off at a fixed duration, every time
Capacity pressureConcurrency or quota stops a lower-priority runMore likely to drop during busy windows

What they share is that you don't hold the initiative over the interruption. That settles the direction of the design. The goal isn't "don't fall over" — it's "keep going even after you fall over." The former assumes control over the environment, and that control isn't yours. The latter only requires that you keep the place where progress lives on your own side.

Handing long-running work to Managed Agents is a choice I reach for gladly. I want to let go of operations I can let go of. But the condition for letting go is this: keep progress outside the sandbox. I draw that line first, before anything else.

The core idea — push progress "outside"

The job fits in one sentence. Every time the agent takes a step, write that step to an external, durable store. When the sandbox disappears, the external store remains. The next run reads it and continues from where the last one stopped.

The important discipline is to externalize as little as possible. It's tempting to save the entire intermediate dataset, but that's heavy and fragile. Only two things need to leave the sandbox:

  1. How far you got — a step index, or the set of already-processed identifiers.
  2. The minimum state needed to resume — the position of the next input, a running counter, an external resource handle.

The intermediate artifacts themselves (summary text, images, partial aggregates) get written as a side effect into a "committed results" table in the external store, and the checkpoint only references them. That keeps the checkpoint light and makes re-reads on resume cheap.

Put differently: the checkpoint is a map, not the cargo. The cargo is dropped at each waypoint (committed results); the map only records how far you've traveled. That separation is what makes the idempotency that follows fall out cleanly.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
A checkpoint that survives sandbox recycling by externalizing only the step index and the minimal resume state
Idempotent resume that never repeats a side effect: the claim-execute-commit phases, with complete working SQLite code
A checkpoint-granularity guide: the measured recovery-time vs cost trade-off between per-step and batched saves
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $15 for lifetime access
View Membership →

Related Articles

API / SDK2026-09-02
Taking stock of Gemini standard API keys before September, across CI, servers, and my own machine
Standard API keys, including restricted ones, stop being accepted during September. Because this changes where keys come from rather than what they say, here is the three-layer inventory I ran across code, deploy settings, and my local machine, plus a dual-path client to switch behind.
API / SDK2026-08-08
A Timeout Was Never Evidence of Failure — Designing Around Blocking Function Calls
When a tool call cannot return until the real-world effect finishes, two habits reverse on you: parallel dispatch and generous timeouts. Measured numbers from a sandbox harness, plus the design that replaces retries with observation.
API / SDK2026-08-02
Measuring a Guard in environment hooks: 46 Microseconds to Decide, 23 Milliseconds to Start
A record of building a destructive-command guard for Managed Agents environment hooks. A regex denylist let 9 of 20 dangerous commands through; argv parsing reached 100 percent detection. The startup cost turned out to be 500 times the decision cost.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links