Skip to content
AI agents

Safe AI Agents: Approvals, Supervisors and Verification

Learn practical patterns for building safe AI agents with approvals, supervisors and verification. Apply proven techniques to protect users and systems.

engineer coding AI agent safety on laptop
Illustration generated with AI.

Developers building AI agents often face the challenge of ensuring that the agents act only within intended boundaries. Without proper safeguards, an agent can execute unintended commands, leak data or compromise systems.

By combining approval workflows, supervisory oversight and formal verification, you can create agents that are not only powerful but also trustworthy and compliant with security policies.

Defining Approval Tokens for Sensitive Actions

In a safe AI agent architecture, every operation that can alter system state or expose data must be gated by an approval token. The token is a short‑lived credential that the agent presents to a central verifier before proceeding. This pattern mirrors the one‑time password (OTP) model used by Carpathron Remote, where a user receives a temporary code that authorizes a session or a privileged command. By adopting a similar approach, developers can enforce a clear separation between the agent’s decision logic and the actual execution of high‑risk actions.

Token Generation Workflow

1. Trigger Request: The agent emits a request for a sensitive operation, such as “deploy firmware to a robot” or “grant admin rights to a user.” The request includes an operation identifier, a timestamp, and a nonce to prevent replay attacks.

2. Signature Creation: The agent signs the request payload with its private key. The signature guarantees authenticity and integrity. The signing algorithm should be at least ECDSA with P‑256 or RSA‑2048, depending on the platform.

3. Token Issuance: A trusted approval service receives the signed request, validates the signature, checks the nonce against a cache, and verifies that the operation is within the agent’s scope. If all checks pass, the service issues a JSON Web Token (JWT) that encodes the operation, the agent’s identity, and an expiration claim (e.g., 5 minutes).

4. Delivery: The token is returned to the agent over a secure channel (TLS 1.3). The agent stores it temporarily and attaches it to the subsequent command payload.

Token Validation Process

When the agent attempts the sensitive action, it forwards the JWT to the target subsystem. The subsystem performs the following steps:

  1. Signature Verification: The subsystem checks the token’s signature against the public key of the approval service.
  2. Claims Inspection: It ensures that the exp claim is still valid, that the aud claim matches the subsystem’s identifier, and that the op claim matches the requested operation.
  3. Replay Protection: The subsystem consults a short‑lived cache (e.g., Redis with TTL) to confirm that the token’s unique identifier (JTI) has not been used before.
  4. Execution Decision: If all checks succeed, the subsystem performs the operation; otherwise it rejects the request with a 403 status code.

Integrating with Carpathron Remote

Carpathron Remote demonstrates a practical implementation of this model through its one‑time password system. When a user initiates a remote session, the app generates a 6‑digit OTP that is valid for 20 minutes. The OTP is transmitted to the remote PC via a secure WebSocket, and the PC validates it before granting control. By extending this mechanism, a safe AI agent can issue operation‑specific tokens that the target device verifies before executing a command. For example, a robot controller could require a token for firmware updates, ensuring that only an approved agent can push new binaries.

Developers can reference the Carpathron Remote source repository on GitHub to observe how the OTP is generated, transmitted, and validated. The same pattern can be adapted to any agent that needs to perform critical operations in a distributed environment.

Implementing short‑lived approval tokens adds a robust layer of security to AI agents, preventing accidental or malicious execution of sensitive actions. By following the generation and validation workflow outlined above, teams can build agents that respect the principle of least privilege while maintaining operational flexibility.

Building a Supervisor Agent to Monitor Behavior

A supervisor agent is a lightweight daemon that runs alongside the primary AI agent, listening to every command issued and every system call made. Its responsibilities are threefold: observe, analyze, and intervene. The architecture is deliberately modular so that each component can be swapped or upgraded without disrupting the overall flow.

Observer Layer

The observer captures events in real time. On Windows it hooks into the Windows Event Log and the Windows Management Instrumentation (WMI) provider, while on Linux it uses inotify and auditd. Each event is wrapped in a JSON payload containing a timestamp, user ID, action type, and a cryptographic hash of the payload for integrity. The observer streams these payloads to the analyzer via a secure WebSocket or a local message queue (e.g., ZeroMQ). Because the observer runs with the same privileges as the agent, it can detect privileged escalations before they occur.

Analyzer Layer

The analyzer applies a rule‑based engine and a lightweight machine‑learning model. Rules are expressed in a declarative DSL that can match on command patterns, file paths, or network destinations. For example, a rule might flag any attempt to write to C:\Windows\System32 or to open a TCP socket on port 22. The ML model, trained on labeled benign and malicious action logs, assigns a risk score to each event. Scores above a configurable threshold trigger the intervention module.

Intervention Layer

When the analyzer flags an anomaly, the intervention module pauses the agent’s execution thread. It presents a modal dialog to the user or sends an email to the administrator with the action details and a one‑time approval code. If the user approves, the action is re‑executed; otherwise it is logged and discarded. The intervention can also inject corrective commands, such as terminating a runaway process or rolling back a file change. All interventions are logged with a tamper‑evident signature so that post‑mortem investigations can trace the decision chain.

Integration with Carpathron Robotics & Coding’s AI Agent Desktop App

Carpathron’s remote desktop app demonstrates this supervisory pattern in a production setting. The app’s AI agent can initiate SSH sessions, transfer files, or launch applications on the host. The supervisor daemon, bundled with the app, monitors every remote command. If the agent attempts to execute a script that modifies system drivers, the supervisor flags it, pauses the session, and requests approval from the remote user. This real‑time gatekeeping prevents accidental or malicious system changes while preserving the agent’s productivity.

Because the supervisor runs locally, it remains functional even when the network connection drops, ensuring that critical safety checks are never bypassed by connectivity issues.

Tip: Deploy the supervisor as a Windows Service or a systemd unit so that it starts automatically with the system and survives reboots without manual intervention.

Implementing Verification via Audit Logs and Replay

Verification of AI agent behavior starts with a tamper‑evident audit log that records every decision made by the agent. The log must capture the context, the decision, and a cryptographic signature that binds the record to the agent’s state at that moment. A typical entry in the log looks like this:

timestamp=2026‑11‑07T14:23:11Z; agent_id=carpathron‑remote‑001; action=execute; command=QLang.run("install‑package –name nginx"); hash=sha256(…); sig=ed25519‑signature

Each log entry is appended to a file that is written to an append‑only storage backend such as a local file system with journaling or a cloud object store that supports immutable objects. The cryptographic hash of the previous entry is stored in the current one, creating a chain that makes any alteration detectable.

QLang: A Minimal Verifiable Action Language

QLang is a lightweight domain‑specific language designed for expressing agent actions that can be executed deterministically. A QLang script is a sequence of commands, each of which has a well‑defined side effect. For example:

1. check‑disk‑usage –threshold 80% 2. if usage > 80% then install‑package –name nginx 3. log‑event –message "nginx installed"

The agent parses the script, evaluates each command, and records the result in the audit log. Because QLang has no implicit state changes beyond those explicitly declared, replaying the script from the log guarantees that the same decisions will be reproduced.

Recording Decisions in a Tamper‑Evident Log

When the agent executes a QLang command, it first writes a log entry with the command string and the intended result. Only after the command succeeds does the agent write a second entry confirming the outcome. If the command fails, the failure is logged with the error code. The log entry is signed with the agent’s private key; the public key is distributed to auditors and the system that verifies the log.

To prevent replay attacks, each entry includes a unique nonce and a timestamp. The log file is rotated daily, and each rotation creates a new root hash that is stored in a secure key‑management service. Auditors can retrieve the root hash and verify the integrity of the entire log chain.

Replay for Post‑Hoc Verification

After an incident or a routine audit, the system can replay the logged decisions to reconstruct the agent’s behavior. The replay engine reads the log sequentially, applies each QLang command to a sandboxed environment, and compares the observed outcome with the recorded result. Discrepancies indicate either a tampered log or a hidden side effect.

The replay process is automated in the Qubitpage Remote product: the remote desktop app can import a log file, run the replay engine, and generate a PDF report that lists each step, the expected outcome, and the actual outcome. If any step fails, the report highlights the mismatch and provides the cryptographic evidence that the log was not altered.

By combining a tamper‑evident audit log with a deterministic action language like QLang, developers can achieve end‑to‑end verification of AI agent decisions. This approach satisfies regulatory requirements for traceability and provides a clear audit trail that can be inspected by human operators or automated verification tools.

Step‑by‑Step: Setting Up an Approval‑Supervisor Loop

Integrating approval tokens, a supervisor agent, and verification into a new project requires a disciplined workflow. Below is a practical sequence that aligns with Qubitpage’s Carpathron Remote framework and the Carpathron Robot Protocol.

  1. Define the Action Scope. List all sensitive actions that the AI agent may trigger (e.g., file deletion, network configuration, robotic arm movement). Assign a unique approval token identifier to each action type. Store these identifiers in a JSON configuration file that the agent reads at startup.
  2. Implement the Token Generator. Create a lightweight Node.js microservice that issues one‑time tokens. The service exposes an HTTPS endpoint /api/token?action=delete_file and returns a JWT signed with a secret known only to the supervisor. Tokens expire after 30 seconds to reduce replay risk.
  3. Embed Token Checks in the Agent. Modify the agent’s action handlers to call the token service before execution. If the token is missing or invalid, the agent logs the attempt and aborts the action. Use the axios library for synchronous HTTP calls to keep the flow simple.
  4. Deploy the Supervisor Agent. Spin up a separate Python process that listens on a Unix domain socket. The supervisor receives action requests, validates the JWT, and logs the event to a PostgreSQL audit table. It also forwards the request to a verification microservice after the action completes.
  5. Set Up Verification via Replay. The verification microservice stores the original request payload, the agent’s response, and a timestamp. It provides a CLI tool carpathron-verify --id 1234 that replays the request against a sandbox environment and compares the outcome with the logged response. Discrepancies trigger an alert email to contact@qubitpage.com.
  6. Integrate with Carpathron Remote. For remote desktop scenarios, enable the optional AI technician feature by passing the agent’s API key to the Carpathron Remote client. The client then presents the supervisor’s approval prompt to the remote user, ensuring that the human operator explicitly authorizes the action.
  7. Automate Testing. Write unit tests that simulate token issuance, agent action, supervisor validation, and verification replay. Use Jest for JavaScript components and Pytest for Python services. Run the suite in a CI pipeline before each release.
  8. Monitor and Iterate. Deploy the system to a staging environment and collect metrics on token usage, supervisor latency, and verification success rate. Adjust token expiration and logging verbosity based on observed patterns.

Tip: Keep the token secret in a Vault or AWS KMS; avoid hard‑coding it in source control to prevent accidental leaks.

Following these steps ensures that every sensitive action passes through a cryptographic approval gate, a real‑time supervisory check, and a post‑hoc verification stage, thereby meeting the strict safety requirements of modern AI deployments.

Comparison Table: Approval, Supervisor, Verification Patterns

When designing safe AI agents, the choice of control pattern depends on operational constraints and security posture. Below is a concise comparison of the three most common patterns—Approval, Supervisor, and Verification—across key criteria that influence deployment decisions.

Criterion Approval Pattern Supervisor Pattern Verification Pattern
Latency (seconds) 0.5–2.0 s (depends on human response time) 0.1–0.5 s (real‑time monitoring) 0.2–1.0 s (post‑action replay)
Implementation Complexity Low (simple token exchange) Medium (continuous monitoring and policy engine) High (audit log ingestion, replay engine, replay‑consistency checks)
Auditability High (each action logged with approval token) High (continuous logs with anomaly flags) Very High (full replay history, deterministic replay validation)
Scalability (agents per host) High (single token per session) Medium (resource overhead per monitored agent) Low (replay engine bottleneck)
Usability for End‑Users Moderate (requires prompt approval) High (transparent monitoring) Low (replay may interrupt workflow)
Compliance Fit (e.g., GDPR, ISO 27001) Good (explicit consent per action) Excellent (continuous oversight) Excellent (complete audit trail)

In practice, many deployments combine patterns to balance performance and security. For example, a Supervisor can flag suspicious actions that trigger an Approval prompt, while a Verification engine periodically replays critical sequences to confirm compliance. The choice hinges on the risk profile: high‑value assets may justify the overhead of verification, whereas routine operations often rely on lightweight approval.

To illustrate how these patterns integrate with existing Qubitpage products, consider the Carpathron Remote application. Its optional AI technician feature exemplifies an Approval pattern—each admin prompt requires a one‑time password and an explicit approval token. Meanwhile, the Carpathron robotics suite uses a Supervisor pattern in its WhatsApp‑controlled agents, continuously monitoring commands for policy violations. Finally, the QuBIOS firmware includes a verification module that replays logged sensor events to validate safety thresholds.

Choosing the right pattern—or a hybrid—requires evaluating latency tolerance, system complexity, audit demands, and user experience. The table above provides a quick reference to inform that decision and align it with organizational risk appetite and regulatory obligations.

Deploying Safe Agents in Production Environments

When a safe AI agent moves from the lab to a live system, the operational envelope expands. The agent must run reliably, consume predictable resources, and expose clear audit trails. A production deployment therefore centers on three pillars: containerization for isolation, resource limits for stability, and monitoring for observability.

Containerization and Orchestration

Packaging an agent in a Docker image guarantees that the runtime environment matches the one used during testing. The image should contain only the agent binary, its configuration files, and a minimal runtime stack. For example, a Carpathron Robotics agent can be built with a base image of python:3.11-slim and a single ENTRYPOINT ["python", "agent.py"] line. Once the image is built, it can be pushed to a registry such as Docker Hub or GitHub Container Registry and deployed to Kubernetes or Docker Swarm. Kubernetes’ Deployment resource automatically restarts pods if an agent crashes, while StatefulSet can be used for agents that require persistent storage.

Resource Limits and Autoscaling

Safe agents often perform CPU‑intensive inference or network‑heavy communication. Defining resources.limits and resources.requests in the pod spec prevents a single agent from exhausting node capacity. A typical limit might be cpu: 500m and memory: 512Mi. Autoscaling can be enabled with HorizontalPodAutoscaler, which watches CPU usage and scales the number of replicas between a defined minimum and maximum. This approach keeps the system responsive during traffic spikes without over‑provisioning hardware.

Observability and Alerting

Every safe agent should emit structured logs and metrics. Using the logging module in Python, logs can be directed to a central aggregator such as Loki or ELK. Metrics like agent_requests_total and agent_error_rate can be exposed via Prometheus endpoints. Alerts can be configured to trigger when error rates exceed a threshold or when resource usage approaches limits. For agents that interact with users, a separate audit log should record approval tokens and supervisor decisions, ensuring traceability.

Secure Communication and Access Control

Agents that expose network services must use TLS to encrypt traffic. A Kubernetes Ingress controller with automatic Let's Encrypt certificates can handle HTTPS termination. For agents that need to authenticate with external services, secrets should be stored in Kubernetes Secrets or HashiCorp Vault, and accessed via environment variables or mounted volumes. This practice keeps credentials out of image layers and source code.

Integration with Carpathron Remote and Robotics

In many production scenarios, a safe agent will be accessed remotely or will control a robot. The Carpathron Remote application provides a secure channel for remote desktop sessions, allowing administrators to observe agent behavior in real time. For robotics deployments, the Carpathron Robotics platform offers a lightweight agent that communicates over the Carpathron Robot Protocol, ensuring that the agent’s decisions are executed on the hardware with minimal latency.

Continuous Deployment and Rollback

Adopting GitOps practices with tools like Argo CD or Flux ensures that any change to the agent’s code or configuration is automatically rolled out to the cluster. Rollback is straightforward: the Git repository retains previous commits, and the operator can revert the deployment to a known good state with a single command. This strategy reduces downtime and guarantees that safe agents remain compliant with the latest approval and supervision rules.

By combining containerization, precise resource limits, comprehensive observability, and secure communication, organizations can deploy safe AI agents that meet operational demands while preserving the integrity of the approval, supervisor, and verification mechanisms established during development.

Frequently asked questions

How do I generate a secure approval token for my agent?

Use the generate-token endpoint in the Qubitpage API, passing your agent’s ID and a JSON Web Token (JWT) signed with your private key. The response includes a short‑lived token that the agent presents when initiating a session. Store the token in a secure vault and rotate it every 24 hours to limit exposure.

What is the role of a supervisor agent in preventing misuse?

A supervisor agent monitors every command issued by a primary agent. It evaluates the command against a whitelist of allowed actions and can block or modify requests that violate policy. The supervisor logs all decisions, enabling real‑time alerts if anomalous behavior is detected.

Can I audit agent decisions after the fact?

Yes. Qubitpage logs every agent interaction in an immutable audit trail stored in a PostgreSQL database. You can query the log via the /audit API, filtering by agent ID, timestamp, or action type. Exporting the data to CSV or JSON facilitates compliance reviews.

How does verification affect agent performance?

Verification introduces a lightweight validation step that checks input integrity and policy compliance before execution. In practice, the overhead is under 10 ms per request, which is negligible for most interactive workflows. The trade‑off is higher confidence that the agent behaves as intended.

Where can I learn more about safe AI agent patterns?

Start with the official Qubitpage documentation at qubitpage.com/docs/agents. The GitHub repository github.com/qubitpage hosts example projects and best‑practice guides. For deeper study, attend Qubitpage’s quarterly webinars on AI safety and review the book “The Architect” by Mircea S. Rusu.

Ensuring Trustworthy AI Agents

Implementing a clear approval workflow is the first step toward reliable AI behavior. Require a human supervisor to review every prompt that triggers administrative actions, and log each approval with a timestamp and user ID. Use role‑based access controls so only authorized personnel can grant elevated privileges, and enforce a one‑time password for remote sessions that involve AI‑assisted troubleshooting. When deploying the optional AI technician in Carpathron Remote, bind the key to the user’s identity and prompt the local operator to confirm each command before execution.

Verification should be continuous. Periodically audit the AI’s decision logs against predefined safety rules, and run automated regression tests that simulate edge cases such as network interruptions or malformed input. Integrate a feedback loop where users can flag unexpected behavior; the system should automatically flag the session for review and trigger a retraining cycle if needed. Finally, maintain an immutable record of all interactions—this audit trail is essential for compliance and for building stakeholder confidence.

By combining strict approvals, real‑time supervision, and systematic verification, you can deploy AI agents that are both powerful and trustworthy. Explore Qubitpage’s solutions to start building secure, AI‑enhanced workflows today.

Written by

Mircea S. Rusu

Founder and engineer of Qubitpage. Support engineer since 2005, CMS developer, former technical consultant at Niguarda Ca' Granda Hospital in Milan, and author of the book “The Architect”.

More about the author →