OpsCanary
gcpcloud runPractitioner

Choosing the Right Execution Environment in Cloud Run

5 min read Google Cloud DocsSep 6, 2026Reviewed for accuracy
Share
PractitionerHands-on experience recommended

Cloud Run exists to simplify the deployment of containerized applications, but the choice of execution environment can make or break your service's performance. With two options available, understanding their differences is crucial for optimizing your application. The first generation execution environment is based on gVisor, offering fast cold start times but limited system call emulation. In contrast, the second generation execution environment uses a microVM, providing full Linux compatibility and superior CPU and network performance.

By default, Cloud Run services do not specify an execution environment, allowing the platform to choose based on the features you use. If you want to control this, you can specify the execution environment using the --execution-environment flag in your deployment commands. For example, you can update an existing service with gcloud run services update SERVICE --execution-environment ENVIRONMENT. Remember, the second generation requires at least 512 MiB of memory, so plan your resource allocation accordingly.

In production, be aware of the trade-offs. If your service experiences bursty traffic or needs to scale quickly, the first generation might be more suitable due to its faster cold start times. Additionally, if your application has low memory requirements, the first generation is the way to go. One critical gotcha is that if your container does not handle SIGTERM properly, it still gets a 10-second grace period to clean up, and you'll be billed for that time. This can lead to unexpected costs if not managed correctly.

Key takeaways

  • Specify the execution environment using the --execution-environment flag during deployment.
  • Use the first generation for bursty traffic or services sensitive to cold start times.
  • Ensure your service has at least 512 MiB of memory for the second generation environment.
  • Monitor your container's SIGTERM handling to avoid unnecessary billing.
  • Understand that the default execution environment is unspecified, which may lead to unexpected behavior.

Why it matters

Choosing the right execution environment can lead to significant performance improvements and cost savings in production. Misconfiguration can result in slow response times or unnecessary charges.

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, needs to scale out fast, or has infrequent traffic causing frequent scale out from zero. Additionally, if your service requires less than 512 MiB of memory, the second generation is not an option.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →
DigitalOceanSponsor

Simple, affordable cloud — VMs, Kubernetes, and managed databases in minutes. Trusted by 600,000+ developers. Spin up a Droplet in 60 seconds.

Try DigitalOcean →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.