Taking Advantage of Cloud Run Sandboxes with Google Apps Script for Google Workspace A developer built an architecture connecting Google Cloud Run Sandboxes (gVisor) directly to Google Apps Script, enabling deterministic Python and Bash execution inside Google Workspace in 200–450 ms with zero-trust micro-isolation and zero idle cost. The approach uses the ggsrun CLI for streaming between the sandbox and Google Drive, extending Workspace automation beyond the V8 runtime's 6-minute timeout and JavaScript-only limits without relying on LLM inference. The work builds on Romin Irani's guide to Cloud Run Sandboxes and the developer's earlier Gemini Managed Agents integration. Deterministic Sub-Second Python and Bash Execution, Zero-Trust gVisor Isolation, and Zero Idle Cost Abstract While secure sandboxes are pivotal for running Generative AI-generated code safely, connecting Google Cloud Run Sandboxes gVisor directly to Google Apps Script unlocks a vastly broader horizon. Beyond executing AI-drafted scripts on the fly, this complementary architecture empowers Google Workspace with deterministic Python data science Pandas, Seaborn and Bash execution in 200–450 ms. With zero-trust micro-isolation, zero-token data ingestion, and zero idle cost, it elevates Workspace automations far beyond standard V8 runtime constraints. Introduction Google Apps Script GAS Ref https://developers.google.com/apps-script is a cornerstone of Google Workspace automation across Sheets, Docs, Forms, and Drive. Yet, developers often hit hard limits. Standard accounts enforce a strict 6-minute timeout. The environment runs only JavaScript on V8, precluding native Linux binaries or external compilers. When an unhandled exception occurs, the entire script halts abruptly. Recently, in my article "Taking Advantage of Gemini Managed Agents with Google Apps Script" Ref https://medium.com/google-cloud/taking-advantage-of-gemini-managed-agents-with-google-apps-script-19215ab8c61f , I showed how to break past these limits by connecting Apps Script to a persistent Linux sandbox provisioned by Gemini Managed Agents Ref https://ai.google.dev/gemini-api/docs/agents . Using my Go CLI tool ggsrun Ref https://github.com/tanaikech/ggsrun for direct streaming between the sandbox and Google Drive, that architecture handles heavy, multi-turn agentic workflows. Examples include Playwright scraping across multiple viewports and audio transcoding with FFmpeg. Gemini Managed Agents excel at autonomous, multi-step reasoning. However, they rely on LLM prompts via the Interactions API. This adds conversational inference overhead, pushing response latencies to several seconds or tens of seconds while burning token quotas such as 200k TPM Ref https://ai.google.dev/gemini-api/docs/rate-limits . Many everyday Workspace automations do not need an LLM. Tasks like mathematical evaluations, string parsing, regular expression matching, and shell commands require deterministic, instant execution without prompt ambiguity or token limits. The breakthrough moment came when I encountered Romin Irani's masterfully crafted and inspiring article, "Safely Running Untrusted Code: A Hands-On Guide to Google Cloud Run Sandboxes" Ref https://medium.com/google-cloud/safely-running-untrusted-code-a-hands-on-guide-to-google-cloud-run-sandboxes-8bbc95d391c7 . In his exceptional guide, Irani brilliantly illuminated how Google Cloud Run Sandboxes leverage gVisor application kernel technology to deliver lightweight, ephemeral micro-isolation for arbitrary code execution with remarkable simplicity and elegance. Reading his hands-on exploration sparked an immediate insight: What if we connect this powerful sandbox directly to Google Apps Script? Could this be the key to supercharging Google Workspace automations with instant, secure dynamic execution? That spark inspired me to plan, design, and thoroughly refine the project presented here. Fundamentally, secure sandboxes have become an indispensable cornerstone in the era of Generative AI. When large language models like Gemini generate code on the fly, they produce untrusted scripts that demand strict execution isolation to shield host environments from unintended side effects, resource exhaustion, or security compromises. I myself have continuously explored and proposed sandboxing approaches for Google Apps Script to safely execute AI-generated code Ref https://medium.com/google-cloud/a-fake-sandbox-for-google-apps-script-a-feasibility-study-on-securely-executing-code-generated-by-cc985ce5dae3 , Ref https://medium.com/google-cloud/exploring-sandboxing-for-ai-generated-google-apps-script-0652a68eb4b7 . Yet, liberating this sandboxed execution capability so that it can be directly orchestrated from Google Apps Script unlocks a vastly broader horizon. It transforms Apps Script from a bounded JavaScript runtime into an agile command center. Beyond safely running AI-generated scripts in real time, it empowers Google Workspace to seamlessly offload high-performance Python and Bash workloads—spanning advanced statistics, scientific plotting with Pandas and Seaborn, and complex data transformations—that were previously unattainable within Apps Script alone. In this article, I introduce this complementary architecture powered by Google Cloud Run Sandboxes --sandbox-launcher Ref https://cloud.google.com/run/docs/configuring/sandboxes . By pairing gVisor Ref https://gvisor.dev/ micro-virtualization with second-generation Cloud Run instances Ref https://cloud.google.com/run , Apps Script can dispatch dynamic Python and Bash scripts over standard REST HTTP calls. The benefits are clear: sub-second execution 200 to 450 ms , zero-trust process isolation, and zero idle maintenance costs. Together, Cloud Run Sandboxes and Gemini Managed Agents give developers a comprehensive automation toolkit for Google Workspace. Architecture: Cloud Run Sandboxes for Google Apps Script Cloud Run Sandboxes compartmentalize untrusted code execution using gVisor application kernel technology. Integrating this infrastructure with Google Apps Script offers four major benefits: Figure 1: Architectural workflow linking Google Apps Script, Cloud Run FastAPI Runner, and gVisor Micro-Sandbox. - Dynamic code execution without image rebuilding : You never need to rebuild or redeploy container images when script logic changes. Apps Script dynamically generates Python or Bash code strings and posts them to the Cloud Run runner for immediate execution. - Crash resilience against runaway scripts : If an offloaded script triggers a segmentation fault or an infinite loop while True: pass , gVisor isolates and terminates only the child process via SIGKILL. The parent FastAPI runner remains healthy and returns a clean JSON error response. - Deterministic sub-second latency : Because the sandbox forks directly inside a running container, it avoids cold VM boots and prompt delays, running guest code in 200 to 450 milliseconds. - Zero-idle cost management : Setting --min-instances=0 allows Cloud Run to scale to zero when idle. Combined with Google Cloud's Always Free tier Ref https://cloud.google.com/run/pricing , everyday automation incurs zero idle maintenance cost. System Architecture and Processing Workflow The architecture connects three layers: the Google Apps Script orchestrator, the Cloud Run FastAPI proxy runner, and the gVisor micro-sandbox isolation layer. For complete, step-by-step setup and deployment instructions, please refer to the detailed guide in the GitHub Repository https://github.com/tanaikech/cloud-run-sandbox-gas . Execution flows through three sequential stages: - Stage 1: Dispatch from Google Apps Script : Apps Script sends an HTTPS POST request with a JSON payload containing the code snippet, language Python or Bash , timeout, and security override flags. Core logic is implemented in gas/Code.js https://github.com/tanaikech/cloud-run-sandbox-gas/blob/master/gas/Code.js and gas/Auth.js https://github.com/tanaikech/cloud-run-sandbox-gas/blob/master/gas/Auth.js . - Stage 2: Execution by FastAPI Proxy Runner : A lightweight Python service on Cloud Run Gen2 cloud run/main.py https://github.com/tanaikech/cloud-run-sandbox-gas/blob/master/cloud run/main.py receives the payload. It invokes /usr/local/gcp/bin/sandbox do --