Google Cloud Run Ephemeral Sandboxes Make LLM Code Execution Boring Again
Anyone building a code interpreter, data-analysis agent, or browser-automation workflow eventually runs into the same unglamorous infrastructure tax: letting an LLM write Python or shell commands on your main API server is asking for credential theft, yet provisioning dedicated Kubernetes pods or paying for third-party microVM SaaS platforms eats margins fast.
On July 10 at WeAreDevelopers World Congress, Google shipped a pragmatic fix in public preview: Cloud Run sandboxes. Instead of asking teams to bolt on another external compute vendor, Cloud Run now lets you spawn isolated, ephemeral execution silos inside the second-generation Cloud Run container you already run.
Sub-second isolation without extra cluster billing
Enabling the feature takes one deployment flag (--sandbox-launcher on gcloud beta run deploy). Once enabled, Cloud Run mounts a lightweight sandbox CLI binary inside your container. From your application code, a subprocess call launches untrusted LLM scripts or headless browsers inside an isolated execution boundary sharing your existing allocated CPU and memory:
import subprocess
def run_untrusted_code(llm_code: str) -> str:
with open("/tmp/generated_script.py", "w") as f:
f.write(llm_code)
result = subprocess.run(
["sandbox", "do", "--", "python3", "/tmp/generated_script.py"],
capture_output=True,
text=True,
timeout=10,
)
return result.stdout if result.returncode == 0 else result.stderr
Google’s demo executed 1,000 start, run, and teardown cycles of untrusted Python at an average of 500 milliseconds per sandbox. Because sandboxes reuse your container’s already-warmed CPU, RAM, and installed Python or system libraries, Google charges zero additional platform fee on top of standard Cloud Run compute billing.
Compare that architecture to hosted agent platforms like Anthropic’s Claude Managed Agents from April, where managed sandbox hours add separate metered billing and keep execution inside a vendor-controlled runtime. Managed sandboxes still make sense if you want batteries-included session storage and don’t run your own backend, yet for engineering teams already deployed on GCP, keeping untrusted code next to your own service dependencies removes an entire network hop and billing line item.
Default security boundaries developers actually need
Where sandbox tools usually burn teams is permissive defaults disguised as developer convenience. Cloud Run sandboxes invert that with three strict zero-trust boundaries out of the box:
- Credential and environment isolation keeps the sandbox blind to the parent service’s environment variables and blocks calls to the Google Cloud metadata server, shutting down the easiest lateral-movement trick for leaked IAM tokens.
- Outbound network egress is denied by default, stopping prompt-injected scripts from phoning home unless you explicitly add
--allow-egress. - Filesystem access gives the sandbox a read-only view of your container image while sending writes into a temporary in-memory overlay that disappears on exit. When multi-turn agent loops need intermediate artifacts saved across runs, you opt in explicitly with
--writeplus--export-tarand--import-tarflags so state moves as an inspectable archive rather than lingering on the host disk.
Google also paired the preview with a CloudRunSandboxCodeExecutor class for its Agent Development Kit (ADK) and added support to vendor-agnostic ComputeSDK so external services can trigger Cloud Run sandboxes remotely. Dropping code_executor=CloudRunSandboxCodeExecutor() onto an ADK Agent definition turns any Gemini-backed data analyst workflow into an isolated Python runner without touching Terraform or provisioning a separate microVM pool.
For engineering teams running production agents on serverless containers, the real payoff isn’t just lower latency. Standardizing on ephemeral, network-blocked subprocess boundaries inside the runtime you already monitor makes code execution predictable to debug, easy to audit, and boring in the best operational sense of the word.