Skip to content

Setup Yoda Executor Using Google Cloud Function Gen2

Kitipong Sirirueangsakul edited this page Sep 16, 2025 · 5 revisions

Google Cloud Platform provides a serverless code execution service called Google Cloud Function (GCF). Yoda's executor runtime can be deployed on GCF to enable code execution in a sandboxed environment.

⚠️ Security Notice:
For security reasons, DO NOT deploy the executor function in your main GCP project.
Instead:

  • Create a separate, isolated GCP project solely for the executor. This ensures it cannot impact your production or sensitive services.
  • Use a custom service account with no permissions to run the Cloud Function. Do not use the default service account, which often has excessive permissions.

Step 1: Create a New Isolated GCP Project

Before deploying the executor, set up a new GCP project to isolate the runtime from your main infrastructure.

  1. Go to the GCP Console and click Create Project.
  2. Name it clearly, e.g., yoda-executor.
  3. After creation, switch into this new project.

Step 2: Create a No-Permission Service Account

  1. Navigate to IAM & Admin > Service Accounts.
  2. Click Create Service Account.
  3. Name it (e.g., yoda-executor) and leave all roles empty. Do not assign any permissions.
  4. Once created, go to the service account’s settings and:
    • Disable key creation if not needed.
    • Restrict user access to only essential members.

Step 3: Create the Cloud Run Function

In the isolated project:

  1. Go to the Cloud Run Functions page.
  2. Click Write a function.

Configure Basic Settings:

  • Type: Function
  • Service name: e.g., yoda-executor
  • Region: Choose your preferred region
  • Runtime: Python 3.13
  • Trigger type: HTTPS
  • Authentication: Allow public access
  • Billing: Request-based
  • Service scaling: Auto scaling
  • Ingress: Depends on how you run node

Step 4: Configure Containers, Volumes, Networking, Security

Under Containers:

  • Resources memory: 1 GiB
  • Request timeout: 12 seconds
  • Maximum concurrent requests per instance: 1

Set these environment variables:

Key Value
MAX_EXECUTABLE 8192
MAX_DATA_SIZE 512

Under Secuirty:

  • Service account: Use the custom service account created in Step 2 (not the default one)

Click Create to proceed.

Step 5: Update Runtime Source Code

  1. Download runtime zip
  2. Set Function entry point to execute
  3. Update main.py to the code from runtime zip
  4. Update requirements.txt to the code from runtime zip

Step 6: Redeploy the Function with new code

Click Save and redeploy. Upon successful deployment, a green check will appear.

Step 7: Test the Function

Get the URL from the function.

You can test the endpoint using curl with the following command

curl --location --request POST '<your_trigger_url>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "executable": "IyEvdXNyL2Jpbi9lbnYgcHl0aG9uMwoKaW1wb3J0IHN5cwoKZGVmIG1haW4oZGF0YSk6CiAgICByZXR1cm4gZGF0YQoKCmlmIF9fbmFtZV9fID09ICJfX21haW5fXyI6CiAgICB0cnk6CiAgICAgICAgcHJpbnQobWFpbigqc3lzLmFyZ3ZbMTpdKSkKICAgIGV4Y2VwdCBFeGNlcHRpb24gYXMgZToKICAgICAgICBwcmludChzdHIoZSksIGZpbGU9c3lzLnN0ZGVycikKICAgICAgICBzeXMuZXhpdCgxKQo=",
    "calldata": "\"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages.\"",
    "timeout": 3000
}'

The expected result should be:

{
    "err": "",
    "returncode": 0,
    "stderr": "",
    "stdout": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages.\n",
    "version": "google-cloud-function:2.0.5"
}