Get System Info

Print OS, Python version, and host details as JSON from a system-info skill script.

Print useful host and Python runtime information as JSON.

get_system_info.py
#!/usr/bin/env python3
"""Print useful host and Python runtime information as JSON."""

import json
import platform
import sys
from datetime import datetime, timezone
from pathlib import Path

# ---------------------------------------------------------------------------
# Create System Information
# ---------------------------------------------------------------------------


def collect_system_info() -> dict[str, str]:
    """Collect portable facts about the current host and Python runtime."""
    return {
        "architecture": platform.machine(),
        "current_time_utc": datetime.now(timezone.utc).isoformat(),
        "hostname": platform.node(),
        "os": platform.system(),
        "os_release": platform.release(),
        "processor": platform.processor(),
        "python_executable": str(Path(sys.executable).resolve()),
        "python_version": platform.python_version(),
    }


# ---------------------------------------------------------------------------
# Run System Information Script
# ---------------------------------------------------------------------------


def main() -> int:
    """Write one machine-readable system information document."""
    print(json.dumps(collect_system_info(), indent=2, sort_keys=True))
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

This is part of the system-info skill bundle. Its location relative to basic.py is sample_skills/system-info/scripts/get_system_info.py; keep the bundle's SKILL.md alongside the scripts directory. The linked setup downloads all required files.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Use the helper

The system-info skill executes this helper as a subprocess with no arguments. The pinned script prints JSON before its current main guard exits.

Full source: cookbook/05_agent_os/23_skills/sample_skills/system-info/scripts/get_system_info.py