GEMINI LABJP
NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20
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 API192Managed Agents6Architecture9Idempotency2Operations9

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 $10 for lifetime access
View Membership →

Related Articles

API / SDK2026-07-14
When a Batch Job Sat in RUNNING for Half a Day: Field Notes on Catching Stalls Early with Per-State Dwell Budgets and Record Reconciliation
When a Gemini Batch job stalls quietly under the shadow of the 24-hour SLA, per-state dwell-time budgets and submitted-vs-completed record reconciliation let you name the stall early. Field notes with real operational numbers.
API / SDK2026-07-04
When Two Managed Agents Fight Over the Same Repo: External Leases and Fencing for Isolated Sandboxes
Every Managed Agents run gets its own isolated sandbox, so a local lock cannot stop two runs from touching the same repo or record. Here is how I serialize them safely with an external lease and a fencing token.
API / SDK2026-07-01
Keeping Unattended Jobs From Failing Silently: A Preflight Gate for Gemini's Platform Changes
Unrestricted API keys are now rejected, the old CLI reached end of life, and the Interactions API is becoming the default entry point. These 2026 platform shifts stop working automation without raising an error. Here is a preflight gate, with runnable code, that catches the failure before the batch runs.
📚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
See all →