On September 15, 2026, all Cloud Composer 1 versions and versions 2.0.x of Cloud Composer 2 will reach their planned end of life. You will not be able to use environments with these versions. We recommend planning migration to Cloud Composer 3. Cloud Composer 2 versions 2.1.x and later are still supported and are not impacted by this change.
GCP_PROJECT_ID with the Project ID
of a project where the VM and the environment that runs the DAG is located.
importdatetimeimportairflowfromairflow.providers.ssh.operators.sshimportSSHOperatorfromairflow.providers.google.cloud.hooks.compute_sshimportComputeEngineSSHHookGCE_INSTANCE='example-compute-instance'GCE_ZONE='us-central1-a'GCP_PROJECT_ID='example-project'withairflow.DAG('composer_compute_ssh_dag',start_date=datetime.datetime(2025,1,1))asdag:ssh_task=SSHOperator(task_id='composer_compute_ssh_task',ssh_hook=ComputeEngineSSHHook(instance_name=GCE_INSTANCE,zone=GCE_ZONE,project_id=GCP_PROJECT_ID,use_oslogin=True,use_iap_tunnel=False,use_internal_ip=True),command='echo This command is executed from a DAG',dag=dag)
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[[["\u003cp\u003eThis page provides instructions on how to connect to a Compute Engine VM from a Directed Acyclic Graph (DAG).\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eComputeEngineSSHHook\u003c/code\u003e is used within the \u003ccode\u003essh_hook\u003c/code\u003e parameter of the \u003ccode\u003eSSHOperator\u003c/code\u003e to establish the connection to the Compute Engine VM.\u003c/p\u003e\n"],["\u003cp\u003eAn example demonstrates using \u003ccode\u003eSSHOperator\u003c/code\u003e to execute a command on a Compute Engine VM instance.\u003c/p\u003e\n"],["\u003cp\u003eTo make it work, users must replace \u003ccode\u003eGCE_INSTANCE\u003c/code\u003e, \u003ccode\u003eGCE_ZONE\u003c/code\u003e, and \u003ccode\u003eGCP_PROJECT_ID\u003c/code\u003e with their respective values.\u003c/p\u003e\n"],["\u003cp\u003eThe content shown on this page is currently for Cloud Composer 2, and it is not yet revised for Cloud Composer 3.\u003c/p\u003e\n"]]],[],null,["# Connect to a Compute Engine VM with SSHOperator\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\n**Cloud Composer 3** \\| [Cloud Composer 2](/composer/docs/composer-2/connect-gce-vm-sshoperator \"View this page for Cloud Composer 2\") \\| [Cloud Composer 1](/composer/docs/composer-1/connect-gce-vm-sshoperator \"View this page for Cloud Composer 1\")\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis page describes how to connect to a Compute Engine VM from a DAG.\n\nCreate a DAG that connects to a Compute Engine VM instance\n----------------------------------------------------------\n\nIn the `ssh_hook` parameter of `SSHOperator`, use\n[`ComputeEngineSSHHook`](https://airflow.apache.org/docs/apache-airflow-providers-google/stable/_api/airflow/providers/google/cloud/hooks/compute_ssh/index.html) with parameters that point to\nthe Compute Engine VM.\n\nThe following example demonstrates how to use\n[`SSHOperator`](https://airflow.apache.org/docs/apache-airflow-providers-ssh/stable/_api/airflow/providers/ssh/operators/ssh/index.html) to run a command on a\nCompute Engine VM instance.\n\nReplace the values:\n\n- `GCE_INSTANCE` with the name of the VM instance.\n- `GCE_ZONE` with the [Compute Engine zone](/compute/docs/regions-zones/regions-zones) where the VM is located.\n- `GCP_PROJECT_ID` with the [Project ID](/resource-manager/docs/creating-managing-projects)\n of a project where the VM and the environment that runs the DAG is located.\n\n import datetime\n\n import airflow\n from airflow.providers.ssh.operators.ssh import SSHOperator\n from airflow.providers.google.cloud.hooks.compute_ssh import ComputeEngineSSHHook\n\n GCE_INSTANCE = 'example-compute-instance'\n GCE_ZONE = 'us-central1-a'\n GCP_PROJECT_ID = 'example-project'\n\n with airflow.DAG(\n 'composer_compute_ssh_dag',\n start_date=datetime.datetime(2025, 1, 1)\n ) as dag:\n\n ssh_task = SSHOperator(\n task_id='composer_compute_ssh_task',\n ssh_hook=ComputeEngineSSHHook(\n instance_name=GCE_INSTANCE,\n zone=GCE_ZONE,\n project_id=GCP_PROJECT_ID,\n use_oslogin=True,\n use_iap_tunnel=False,\n use_internal_ip=True),\n command='echo This command is executed from a DAG',\n dag=dag)\n\nWhat's next\n-----------\n\n- [Add and update DAGs](/composer/docs/composer-3/manage-dags)\n- [Schedule and trigger DAGs](/composer/docs/composer-3/schedule-and-trigger-dags)\n- [Troubleshooting DAGs](/composer/docs/composer-3/troubleshooting-dags)"]]