CGI (Common Gateway Interface) allows web servers to execute scripts and return their output as HTTP responses.
CGI mode is primarily supported by the Python and Perl SDKs. Compiled languages (Go, C++, Java) are better served by their built-in HTTP servers. TypeScript and Ruby can use CGI via their respective interpreters but this is uncommon.
Benefits:
Drawbacks:
The SDK detects CGI mode via the GATEWAY_INTERFACE environment variable:
Make scripts executable:

nginx doesn’t natively support CGI, but you can use FastCGI with fcgiwrap:
In CGI mode, the SDK needs to know the external hostname for generating URLs:
Or set environment variable:
Use swaig-test to simulate CGI environment:
The SDK checks basic auth in CGI mode:
If authentication fails, returns 401 with WWW-Authenticate header.
For shared hosting where you can’t install system packages:
Install packages locally:
Keep same code, use fcgiwrap or gunicorn. Better performance, persistent processes.
Same code works - just run differently (python agent.py instead of CGI). Add systemd service, nginx reverse proxy.
Same code works with minor changes. Add Lambda handler wrapper. Deploy to AWS/GCP/Azure.