Skip to main content

Python SDK for CMDOP agent interaction

Project description

cmdop

Programmatic access to any machine. No SSH, no VPN, no open ports.

PyPI Python License

from cmdop import CMDOPClient

with CMDOPClient.remote(api_key="cmd_xxx") as client:
    # Execute commands on remote server
    session = client.terminal.create()
    client.terminal.send_input(session.session_id, "docker ps\n")

    # Read/write files
    logs = client.files.read("/var/log/app.log")
    client.files.write("/tmp/config.json", b'{"debug": true}')

One API key. Any machine. Full control.

Use Cases

AI Agents with Real Infrastructure Access

# Give your AI agent actual server access
def ai_agent_tool(command: str) -> str:
    with CMDOPClient.remote(api_key=API_KEY) as client:
        session = client.terminal.create()
        client.terminal.send_input(session.session_id, f"{command}\n")
        time.sleep(2)
        history = client.terminal.get_history(session.session_id)
        return history.data.decode()

# Claude/GPT can now execute real commands
result = ai_agent_tool("kubectl get pods")

CI/CD & Deployment

# Deploy without Ansible, Fabric, or SSH keys
def deploy(server_key: str, version: str):
    with CMDOPClient.remote(api_key=server_key) as client:
        client.terminal.execute(f"docker pull myapp:{version}")
        client.terminal.execute("docker-compose up -d")

        # Verify deployment
        logs = client.files.read("/var/log/myapp/startup.log")
        assert b"Started successfully" in logs

Remote Monitoring & Debugging

# Collect logs from fleet of servers
async def collect_logs(server_keys: list[str]):
    async with asyncio.TaskGroup() as tg:
        for key in server_keys:
            tg.create_task(fetch_logs(key))

async def fetch_logs(api_key: str):
    async with AsyncCMDOPClient.remote(api_key=api_key) as client:
        return await client.files.read("/var/log/nginx/error.log")

Edge/IoT Device Management

# Update config on thousands of devices
for device_key in device_fleet:
    with CMDOPClient.remote(api_key=device_key) as client:
        client.files.write("/etc/myapp/config.yml", new_config)
        client.terminal.execute("systemctl restart myapp")

Customer Support with Direct Access

# Support agent can inspect customer's machine (with permission)
def diagnose_customer(customer_agent_key: str):
    with CMDOPClient.remote(api_key=customer_agent_key) as client:
        # Check disk space
        result = client.files.list("/")

        # Read app logs
        logs = client.files.read("~/Library/Logs/MyApp/error.log")

        # Check running processes
        session = client.terminal.create()
        client.terminal.send_input(session.session_id, "ps aux | grep myapp\n")

Installation

pip install cmdop

Connection Modes

# Remote — via cloud relay (any machine, anywhere)
client = CMDOPClient.remote(api_key="cmd_xxx")

# Remote — specific agent
client = CMDOPClient.remote(api_key="cmd_xxx", agent_id="uuid-here")

# Local — direct IPC with agent on same machine
client = CMDOPClient.local()

Async Support

import asyncio
from cmdop import AsyncCMDOPClient

async def main():
    async with AsyncCMDOPClient.remote(api_key="cmd_xxx") as client:
        session = await client.terminal.create()
        await client.terminal.send_input(session.session_id, "whoami\n")

        files = await client.files.list("/home")
        content = await client.files.read("/etc/hostname")

asyncio.run(main())

API Reference

Terminal Service

Method Description
create(shell, cols, rows) Create terminal session
send_input(session_id, data) Send input/commands
resize(session_id, cols, rows) Resize terminal
send_signal(session_id, signal) Send signal (SIGINT, SIGTERM)
get_history(session_id, lines) Get output history
close(session_id) Close session

Files Service

Method Description
list(path, page_size) List directory
read(path) Read file contents
write(path, content) Write file
delete(path, recursive) Delete file/directory
copy(src, dst) Copy file
move(src, dst) Move/rename
mkdir(path, parents) Create directory
info(path) Get file metadata

Error Handling

from cmdop.exceptions import (
    AgentOfflineError,      # Agent not connected to cloud
    AgentNotRunningError,   # Local agent not running
    AuthenticationError,    # Invalid API key
    SessionNotFoundError,   # Terminal session expired
    FileNotFoundError,      # File doesn't exist
    PermissionDeniedError,  # No access to file/command
)

try:
    with CMDOPClient.remote(api_key="cmd_xxx") as client:
        client.files.read("/etc/shadow")
except PermissionDeniedError:
    print("Access denied")
except AgentOfflineError:
    print("Agent not connected")

How It Works

  1. Install CMDOP Agent on target machine
  2. Agent connects to cloud relay (outbound only, no open ports)
  3. SDK connects to cloud relay with API key
  4. Commands routed through relay to agent
  5. Results returned through same secure channel
[Your Code] → [Cloud Relay] → [Agent] → [Target Machine]
    SDK          grpc.cmdop.com    Outbound only

Security

  • All traffic encrypted (gRPC over TLS)
  • Agent only makes outbound connections
  • API keys scoped per agent/team
  • No SSH keys or credentials to manage
  • Audit logging available

Requirements

  • Python 3.10+
  • Running CMDOP agent on target machine

Links

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmdop-0.1.1.tar.gz (119.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cmdop-0.1.1-py3-none-any.whl (213.5 kB view details)

Uploaded Python 3

File details

Details for the file cmdop-0.1.1.tar.gz.

File metadata

  • Download URL: cmdop-0.1.1.tar.gz
  • Upload date:
  • Size: 119.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for cmdop-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6729c788835e49ea352a7f916cfa319843fa3356af97c4a498a67dfaa8f8f555
MD5 7323733b44e07c30c9012399aa4dd86e
BLAKE2b-256 35788331a97b8b17856757959ce07238aeff4e66ab791bd251505ce829b355a1

See more details on using hashes here.

File details

Details for the file cmdop-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cmdop-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 213.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for cmdop-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1fd5b586a6eeab3309a52d9ee9440a0613734c6af9131fa61194485ab6c8aa55
MD5 3db629a9a801da348b568de384de4d41
BLAKE2b-256 9b4c1e57541ff048867edad9d91c9dc68fa1ebb2bba8097f4a42131a1e5d6e3d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page