arXiv:2610.06001cs.SEOct 2026

Manuscript Offprint

arXiv:2610.06001

AgentSpy: Making AI Agent Behavior Observable

Christoph Bühler, Matteo Biagiola, Luca Di Grazia, Guido Salvaneschi

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

CHRISTOPH BÜHLER, University of St. Gallen, Switzerland

MATTEO BIAGIOLA, University of St. Gallen and Università della Svizzera italiana (USI), Switzerland

LUCA DI GRAZIA, University of St. Gallen, Switzerland

GUIDO SALVANESCHI, University of St. Gallen, Switzerland

AI agents built on large language models (LLMs) run shell commands, read and write files, and reach the network, typically with their user's privileges. However, what an agent does during an execution is difficult to understand: tests assert on the result, and the agent's trajectory records only what the agent reports about itself. Consequently, the agent's recorded trajectory may omit behavior executed by its subprocesses.

We present AgentSpy, an approach that observes an agent from outside the agent. AgentSpy runs the agent in an isolated environment, configured by a declarative specification, and records the system calls and network traffic of the agent and of every process it executes. Based on this monitoring, AgentSpy supports two families of analyses: conformance analyses, which measure obligations, i.e., what an agent execution should do, and safety analyses, which check prohibitions, i.e., what an agent execution must never do. We instantiate one analysis of each family. The reliability analysis uses a rule-based approach to build a summary of each run, consisting of environment resources the agent uses, i.e., the commands it executed, the files it accessed, and the hosts it contacted. The security analysis applies deterministic rules to the system calls of an execution.

For reliability analysis, we evaluated AgentSpy on 77 tasks with the codex harness and three recent LLMs, and executed each task three times. Sets of repeated runs of the same task are more similar than sets that include runs of another task in 92.2% of the comparisons. Among the tasks for which all three runs pass outcome-based tests, we found that in 18% of the cases the agent performs activities that are unrelated to the task, reads the grading files in 7% of the cases, and does not use the developers' guidance in 17% of the cases. For security analysis, the generic rules of AgentSpy detects four out of five categories of attacks we considered, with no false positives across 50 runs.

CCS Concepts: • Software and its engineering → Software testing and debugging.

Additional Key Words and Phrases: AI Agents, Dynamic Analysis, Behavior Analysis, Agent Security

ACM Reference Format:

Christoph Bühler, Matteo Biagiola, Luca Di Grazia, and Guido Salvaneschi. 2026. AgentSpy: Making AI Agent Behavior Observable. 1, 1 (October 2026), 22 pages. https://doi.org/10.1145/nnnnnnn.nnnnnnn

1 Introduction

AI agents built on large language models (LLMs) carry out tasks autonomously: they call tools, run shell commands, read and write files, and reach the network [20], and they are now used across many fields [4]. An agent that runs on a user’s machine typically acts with the user’s privileges, so it can also take actions the user did not intend, including security-sensitive actions.

Authors' Contact Information: Christoph Bühler, christoph.buehler@unisg.ch, University of St. Gallen, St. Gallen, SG, Switzerland; Matteo Biagiola, matteo.biagiola@usi.unisg.ch, University of St. Gallen and Università della Svizzera italiana (USI), St. Gallen and Lugano, SG and TI, Switzerland; Luca Di Grazia, work@lucadigrazia.com, University of St. Gallen, St. Gallen, SG, Switzerland; Guido Salvaneschi, guido.salvaneschi@unisg.ch, University of St. Gallen, St. Gallen, SG, Switzerland.

Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from permissions@acm.org.

© 2026 Copyright held by the owner/author(s). Publication rights licensed to ACM.

ACM XXXX-XXXX/2026/10-ART

https://doi.org/10.1145/nnnnnnn.nnnnnnn

, Vol. 1, No. 1, Article . Publication date: October 2026.

What an agent does during an execution is, however, difficult to understand for its user. The user sees the result and the agent's trajectory, i.e., the log of reasoning steps, actions, and tool outputs that the agent records about itself [12], but neither shows what the programs the agent executed actually do. This invisibility has started to matter in practice. In September 2026, OpenAI began disclosing cases in which its agents took misaligned actions [39]. In one case, an agent that had already retrieved the correct data locally uploaded it to a public paste service, without authorization, only to obtain a URL its browser tool could cite [41]; in another, agents jointly building a spreadsheet were required to use local files only, but a faulty environment kept them from reading each other's files, so they passed the spreadsheet through a public temporary file-hosting service [40].

Existing work does not address this observability problem. Outcome-based benchmarks check the final result [33], so an agent execution can pass every test while also performing activities unrelated to the task (similar to the cases above). Static analyzers scan the instructions and scripts that are given to an agent for unintended behavior before the agent runs [27, 44, 10], but cannot observe what the agent does at runtime. Trajectory analyses [42, 35, 36] rely on the agent's own record, which is incomplete: its smallest unit of observation is a single action, so when the agent runs a helper script that reads ~/.ssh and uploads the keys, the trajectory records one command and none of the files the script reads or the hosts it contacts. The record also holds only what the agent reports, so it is evidence only as far as the agent is cooperative. Some model providers additionally return the reasoning steps encrypted, which leaves the trajectory with actions and no thoughts. Overall, interpreting the trajectory typically relies on LLM-as-a-judge systems [42], which are non-deterministic, may miss details [24], and can be misled by adversarial text in tool outputs that the judge reads as part of the trajectory [23].

In this paper, we present AgentSpy, a rule-based approach that observes what an AI agent does at the system level. AgentSpy runs the agent in an isolated environment configured by what we call an execution kind: a declarative specification of the environment, of the agent and its parameters, and of the observation steps, so that the conditions of every execution are explicit. Inside the environment, AgentSpy records system calls and network traffic of the agent and of every executed process. Observing at the boundary of the operating system has three advantages. The evidence is complete at this boundary: every program started, file accessed, and host contacted is recorded, whether the agent acted directly, delegated the action to a script, or was steered into it by injected instructions. The evidence is also deterministic and independent of the agent: it does not rely on the agent's account of itself, and it requires no agent instrumentation.

AgentSpy’s analyses of an agent execution belong to two families, which mirror the classic distinction between liveness and safety [5]: conformance analyses measure obligations, i.e., what an execution should do, and safety analyses check prohibitions, i.e., what an execution must never do. The reliability analysis is a conformance analysis: it measures obligations such as following the guidance that developers provide for the task; whether an execution met an obligation is known only once the execution ends. The reliability analysis summarizes each execution as a star graph that characterizes three resource types, i.e., the commands executed, the files read or written, and the hosts contacted. It measures how much of the guidance an execution used, and it compares repeated executions of the same task through their star graphs, which shows how consistently the agent behaves. The security analysis is a safety analysis: it checks prohibitions such as reading secrets and private keys. A single system call is enough to report a violation, so the security analysis applies deterministic rules to the system calls of an agent execution.

Two recent systems also observe agents at the system level, but each only covers part of what AgentSpy supports. AgentSight [58] matches each action of an agent to the LLM message that led to it. A second LLM then reads this record of one execution, and decides whether something went wrong, such as a prompt injection or a reasoning loop. The reliability analysis of AgentSpy, on the other hand, supports multiple executions, via graph similarity. SkillDetonate [29] audits a skill before it is installed. It takes as input the skill, and starts an agent session in which the agent sees only the files of the skill, and placeholders instead of the contents of sensitive files. It reports a leak when data derived from a placeholder is sent to a host that is not on a list of trusted hosts, and a violation when the skill writes outside allowed directories or installs, downloads, or runs a program from an untrusted source. Differently, the security analysis of AgentSpy starts from a task that an agent solves with the skill, and the execution environment is a microVM with a full operating system. AgentSpy relies on deterministic rules over system calls, which are applicable to any agent execution, and each alert reports the rule that matched, the system call, and the process that triggered it.

We evaluated AgentSpy on two benchmarks, SkillsBench for the reliability analysis (77 tasks) and Skill-Inject for the security analysis (5 attack categories), with four recent LLMs running in the codex harness, and multiple executions to account for non-determinism [43, 11]. We show that the star graph summary reliably distinguishes agent executions: sets of repeated executions of a task are more similar than sets that include executions of another task in 92.2% of the comparisons. Among the tasks whose executions all pass test cases provided by SkillsBench, our analysis reveals that the agent performs activities unrelated to the task in 18% of the cases, reads the grading files of the benchmark in 7%, and reaches the result without the guidance that developers provide through skills in 17%, which shows that the reliability analysis complements test cases. The generic rules of the security analysis flag four of the five attack categories in malicious skills, and raise no alert on the execution of benign tasks. Finally, AgentSpy does not add a significant overhead, since the runtime of the agent shows no significant difference without monitoring (p-value ≥\geq 0.16).

This paper makes the following contributions:

  • AgentSpy, an approach that runs an agent in an isolated environment under a declarative execution kind, and records system calls and network traffic of the agent and of every process it spawns.

  • Two deterministic analyses built on AgentSpy, one of each family: (i) the reliability analysis, a conformance analysis that measures how far agent executions meet their obligations, and (ii) the security analysis, a safety analysis that checks prohibitions by applying rules to system calls.

  • An evaluation on two benchmarks, four LLMs, and multiple executions, which shows that the reliability analysis complements test cases, that the security analysis reliably detects different attack categories, and that AgentSpy adds no significant overhead.

References (47)