Manage runtime environments and worker registration
The Environments Service enables you to manage runtime environments for agent and team execution. Environments provide isolated execution contexts with their own worker pools, configurations, and resources.
from kubiya import ControlPlaneClientclient = ControlPlaneClient()# List all environmentsenvironments = client.environments.list()# Get a specific environmentenvironment = client.environments.get(environment_id="env-uuid")# Create a new environmentenv_data = { "name": "Production", "description": "Production environment", "status": "active"}environment = client.environments.create(env_data)# Get worker registration commandworker_cmd = client.environments.get_worker_command(environment_id=environment['id'])print(f"Worker command: {worker_cmd['command']}")
# List all environmentsenvironments = client.environments.list()# List with status filteractive_envs = client.environments.list(status_filter="active")provisioning_envs = client.environments.list(status_filter="provisioning")ready_envs = client.environments.list(status_filter="ready")error_envs = client.environments.list(status_filter="error")
Parameters:
status_filter (str, optional): Filter by status: ‘active’, ‘inactive’, ‘provisioning’, ‘ready’, or ‘error’
Get the registration command for workers in an environment:
Copy
Ask AI
worker_info = client.environments.get_worker_command(environment_id="env-uuid")print(f"Worker Token: {worker_info['worker_token']}")print(f"Command: {worker_info['command']}")print(f"Namespace: {worker_info['temporal_namespace']}")# The command will be similar to:# kubiya worker start --token <worker-token> --environment <env-name>
Parameters:
environment_id (str, required): Environment UUID
Returns: Dictionary containing:
command (str): Full worker start command
worker_token (str): Worker authentication token
temporal_namespace (str): Temporal namespace
environment_name (str): Environment name
Copy the worker command and run it on your worker machines to register them with the environment.
# On your worker machine, run the command provided:kubiya worker start --token eyJhbGc... --environment production# Or with Docker:docker run -d \ --name kubiya-worker \ kubiya/worker:latest \ start --token eyJhbGc... --environment production
import time# Create environmentenv = client.environments.create({ "name": "New Environment", "description": "Newly provisioned environment"})# Poll until readyprint("Waiting for environment provisioning...")while True: current = client.environments.get(environment_id=env['id']) status = current['status'] print(f"Status: {status}") if status == 'ready' or status == 'active': print("Environment ready!") break elif status == 'error': print("Provisioning failed!") break time.sleep(5)