feat: add get_execution_environment() API for managed deployments

Adds a simple API that lets custom nodes detect whether they are
running in a local, cloud, or remote environment.  Managed deployments
set the COMFY_EXECUTION_ENVIRONMENT env var; the default is "local".

This enables node authors to implement graceful degradation - for
example, skipping model downloads when models are pre-provisioned, or
disabling features that require local hardware.
This commit is contained in:
Deep Mehta
2026-03-18 19:23:59 -07:00
parent f6b869d7d3
commit 70340d4dda

View File

@@ -1453,3 +1453,22 @@ def normalize_image_embeddings(embeds, embeds_info, scale_factor):
start_idx = info["index"]
end_idx = start_idx + info["size"]
embeds[:, start_idx:end_idx, :] /= scale_factor
_VALID_ENVIRONMENTS = {"local", "cloud", "remote"}
def get_execution_environment():
"""Return the current execution environment.
Reads the COMFY_EXECUTION_ENVIRONMENT environment variable. Managed
deployments (e.g. Comfy Cloud) set this variable so that custom nodes
can adapt their behaviour at runtime — for example, skipping model
downloads when models are pre-provisioned.
Returns:
str: One of "local" (default), "cloud", or "remote".
"""
value = os.environ.get("COMFY_EXECUTION_ENVIRONMENT", "local").lower().strip()
if value not in _VALID_ENVIRONMENTS:
return "local"
return value