Skip to main content

Environment Variables

Environment Variables

Summary: Complete reference for all environment variables used by the SignalWire Agents SDK.

Overview

CategoryPurpose
AuthenticationBasic auth credentials
SSL/TLSHTTPS configuration
ProxyReverse proxy settings
SecurityHost restrictions, CORS, rate limiting
LoggingLog output control
SkillsCustom skill paths
ServerlessPlatform-specific settings

Authentication Variables

VariableTypeDefaultDescription
SWML_BASIC_AUTH_USERstringAuto-generatedUsername for HTTP Basic Authentication
SWML_BASIC_AUTH_PASSWORDstringAuto-generatedPassword for HTTP Basic Authentication

Note: If neither variable is set, credentials are auto-generated and logged at startup.

SSL/TLS Variables

VariableTypeDefaultDescription
SWML_SSL_ENABLEDbooleanfalseEnable HTTPS ("true", "1", "yes")
SWML_SSL_CERT_PATHstringNonePath to SSL certificate file (.pem/.crt)
SWML_SSL_KEY_PATHstringNonePath to SSL private key file (.key)
SWML_DOMAINstringNoneDomain for SSL certs and URL generation
SWML_SSL_VERIFY_MODEstringCERT_REQUIREDSSL certificate verification mode

Proxy Variables

VariableTypeDefaultDescription
SWML_PROXY_URL_BASEstringNoneBase URL when behind reverse proxy
SWML_PROXY_DEBUGbooleanfalseEnable proxy request debug logging

Warning: Setting SWML_PROXY_URL_BASE overrides SSL configuration and port settings.

Security Variables

VariableTypeDefaultDescription
SWML_ALLOWED_HOSTSstring*Comma-separated allowed hosts
SWML_CORS_ORIGINSstring*Comma-separated allowed CORS origins
SWML_MAX_REQUEST_SIZEinteger10485760Maximum request size in bytes (10MB)
SWML_RATE_LIMITinteger60Rate limit in requests per minute
SWML_REQUEST_TIMEOUTinteger30Request timeout in seconds
SWML_USE_HSTSbooleantrueEnable HTTP Strict Transport Security
SWML_HSTS_MAX_AGEinteger31536000HSTS max-age in seconds (1 year)

Logging Variables

VariableTypeDefaultDescription
SIGNALWIRE_LOG_MODEstringautoLogging mode: "off", "stderr", "default", "auto"
SIGNALWIRE_LOG_LEVELstringinfoLog level: "debug", "info", "warning", "error", "critical"

Skills Variables

VariableTypeDefaultDescription
SIGNALWIRE_SKILL_PATHSstring""Colon-separated paths for custom skills

Serverless Platform Variables

AWS Lambda

VariableDefaultDescription
AWS_LAMBDA_FUNCTION_NAMEunknownFunction name (used for URL construction and logging)
AWS_LAMBDA_FUNCTION_URLConstructedFunction URL (if not set, constructed from region and function name)
AWS_REGIONus-east-1AWS region for Lambda execution
LAMBDA_TASK_ROOTNoneLambda environment detection variable

Google Cloud Functions

VariableDefaultDescription
GOOGLE_CLOUD_PROJECTNoneGoogle Cloud Project ID
GCP_PROJECTNoneAlternative to GOOGLE_CLOUD_PROJECT
GOOGLE_CLOUD_REGIONus-central1Google Cloud region
FUNCTION_REGIONFalls back to GOOGLE_CLOUD_REGIONCloud function region
FUNCTION_TARGETunknownCloud function target/entry point name
K_SERVICEunknownKnative/Cloud Run service name
FUNCTION_URLNoneCloud function URL (used in simulation)

Azure Functions

VariableDefaultDescription
AZURE_FUNCTIONS_ENVIRONMENTNoneEnvironment detection variable
WEBSITE_SITE_NAMENoneAzure App Service site name (used to construct URLs)
AZURE_FUNCTIONS_APP_NAMENoneAlternative to WEBSITE_SITE_NAME
AZURE_FUNCTION_NAMEunknownAzure Function name
FUNCTIONS_WORKER_RUNTIMENoneAzure Functions worker runtime detection
AzureWebJobsStorageNoneAzure Functions storage connection detection

CGI Mode

VariableDefaultDescription
GATEWAY_INTERFACENoneCGI environment detection variable
HTTP_HOSTFalls back to SERVER_NAMEHTTP Host header value
SERVER_NAMElocalhostServer hostname
SCRIPT_NAME""CGI script path
PATH_INFO""Request path info
HTTPSNoneSet to on when using HTTPS
HTTP_AUTHORIZATIONNoneAuthorization header value
REMOTE_USERNoneAuthenticated username
CONTENT_LENGTHNoneRequest content length

Quick Reference

Commonly Configured

VariableUse Case
SWML_BASIC_AUTH_USER / SWML_BASIC_AUTH_PASSWORDSet explicit credentials
SWML_PROXY_URL_BASEWhen behind a reverse proxy
SWML_SSL_ENABLED / SWML_SSL_CERT_PATH / SWML_SSL_KEY_PATHFor direct HTTPS
SIGNALWIRE_LOG_LEVELAdjust logging verbosity
SIGNALWIRE_SKILL_PATHSLoad custom skills

Production Security

VariableRecommendation
SWML_ALLOWED_HOSTSRestrict to your domain(s)
SWML_CORS_ORIGINSRestrict to trusted origins
SWML_RATE_LIMITSet appropriate limit
SWML_USE_HSTSKeep enabled (default)

Example .env File

## Authentication
SWML_BASIC_AUTH_USER=agent_user
SWML_BASIC_AUTH_PASSWORD=secret_password_123

## SSL Configuration
SWML_SSL_ENABLED=true
SWML_DOMAIN=agent.example.com
SWML_SSL_CERT_PATH=/etc/ssl/certs/agent.crt
SWML_SSL_KEY_PATH=/etc/ssl/private/agent.key

## Security
SWML_ALLOWED_HOSTS=agent.example.com
SWML_CORS_ORIGINS=https://app.example.com
SWML_RATE_LIMIT=100

## Logging
SIGNALWIRE_LOG_MODE=default
SIGNALWIRE_LOG_LEVEL=info

## Custom Skills
SIGNALWIRE_SKILL_PATHS=/opt/custom_skills

Loading Environment Variables

## Using python-dotenv
from dotenv import load_dotenv
load_dotenv()

from signalwire_agents import AgentBase
agent = AgentBase(name="my-agent")
## Using shell
source .env
python agent.py

## Using swaig-test
swaig-test agent.py --env-file .env --dump-swml

Environment Detection

The SDK automatically detects the execution environment:

from signalwire_agents.core.logging_config import get_execution_mode

mode = get_execution_mode()
## Returns: "server", "lambda", "cgi", "google_cloud_function", or "azure_function"