detect-agent
raw JSON → 0.2.0 verified Sat May 09 auth: no python
Library to detect if Python code is running inside an AI agent (e.g., ChatGPT, Claude, Cursor agent) or automated development environment. Current version: 0.2.0. Release cadence: irregular.
pip install detect-agent Common errors
error ModuleNotFoundError: No module named 'detect_agent' ↓
cause Package name has hyphen, but Python module uses underscore. Importing as 'detect-agent' fails.
fix
Use
from detect_agent import is_running_from_agent (underscore, not hyphen). error AttributeError: module 'detect_agent' has no attribute 'is_running_from_pi_agent' ↓
cause Function only exists in version 0.2.0 and later; older versions lack it.
fix
Upgrade detect-agent to 0.2.0 with
pip install --upgrade detect-agent. Warnings
gotcha The detection logic relies on environment variables (e.g., CURSOR_ENV, GITHUB_COPILOT) that can be spoofed or absent, leading to false negatives/positives. ↓
fix Do not rely solely on this library for security-critical decisions; use it for soft gating.
deprecated The function `is_running_from_pi_agent` was added in 0.2.0; older versions do not have it. ↓
fix Upgrade to 0.2.0 or check version before calling.
gotcha The library may not detect all agents; it is limited to a curated list of known environment signals. ↓
fix Contribute upstream or extend detection logic locally.
Imports
- is_running_from_agent
from detect_agent import is_running_from_agent - is_running_from_pi_agent
from detect_agent import is_running_from_pi_agent
Quickstart
from detect_agent import is_running_from_agent
if is_running_from_agent():
print('Running inside an AI agent environment')
else:
print('Not running inside an AI agent')