OpsCanary
Back to daily brief
gcpcloud runPractitioner

Choosing the Right Execution Environment in Cloud Run

5 min read Google Cloud DocsApr 23, 2026
PractitionerHands-on experience recommended

Cloud Run exists to streamline the deployment of containerized applications, but choosing the right execution environment is crucial for optimizing performance and managing costs. The execution environments determine how your applications run, impacting cold start times, memory requirements, and overall responsiveness.

By default, Cloud Run selects an execution environment based on the features you use. The first generation execution environment is built on gVisor, providing fast cold start times but only emulating most operating system calls. In contrast, the second generation utilizes a microVM, offering full Linux compatibility, faster CPU and network performance, and support for network file systems. If you don’t specify an execution environment, Cloud Run decides for you, which could lead to unexpected performance characteristics.

In production, you need to be aware of the memory requirements and performance implications of each environment. The second generation requires at least 512 MiB of memory, which can be a limitation for lightweight applications. If your service experiences bursty traffic or has infrequent usage, the first generation may be more suitable, as it scales out quickly and handles cold starts better. Remember, if your container fails to catch SIGTERM, it still gets 10 seconds to clean up, and those seconds are billable. This can lead to unexpected costs if not managed properly.

Key takeaways

  • Understand the differences between first and second generation execution environments.
  • Specify the execution environment explicitly to avoid unexpected performance issues.
  • Be aware that the second generation requires at least 512 MiB of memory.
  • Monitor your service's traffic patterns to choose the right execution environment.
  • Catch SIGTERM in your containers to avoid unnecessary billing during shutdown.

Why it matters

Choosing the correct execution environment can lead to significant performance improvements and cost savings in production. The right choice ensures your applications respond quickly and efficiently to user demands.

Code examples

gcloud
gcloud run services update SERVICE --execution-environment ENVIRONMENT
gcloud
gcloud run deploy --image IMAGE_URL --execution-environment ENVIRONMENT
YAML
1apiVersion: serving.knative.dev/v1
2kind: Service
3metadata:
4  name: SERVICE
5spec:
6  template:
7    metadata:
8      annotations:
9        run.googleapis.com/execution-environment: ENVIRONMENT

When NOT to use this

You should use the first generation if your Cloud Run service has bursty traffic and needs to scale out fast, or if it has infrequent traffic that causes frequent scale out from zero. Avoid the second generation if your service requires less than 512 MiB of memory.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.