Agent Instruction Injection: Entry Points and Configuration Guardrails

    This article breaks agent instruction injection into five actionable checks: entry-point control, configuration integrity, separation of prompt and execution, outbound allowlisting, and rotation on discovery. It explains how untrusted workspaces and project instruction files can rewrite global configuration, and provides practical guardrails, a configuration drift pseudocode example, and a control matrix for engineering teams.

    Agent Instruction Injection: Entry Points and Configuration Guardrails

    1. The Real Issue: Not a Deceived Model, but a Broken Execution Boundary

    A security research organization once published a cross-product reproduction report: a web page could write a seemingly ordinary project instruction file into a user’s downloads directory; after the user started a coding Agent in that directory, the Agent would read the file as project standards, further modify its own global configuration, register an external tool service, and eventually pull and execute a malicious dependency package in a later task. The report emphasized that this chain could be reproduced across different AI coding tools. Therefore, it should not be attributed simply to a model flaw at one vendor, but should be viewed as a structural problem that follows from what an AI Agent is.

    The implication for engineering teams is this: if the risk comes from the Agent reading workspace instructions by design, merging configuration by design, and calling external tools by design, then vendor patches alone are unlikely to cover every combination path. A more realistic approach is to break this risk into gate items that can be detected, blocked, and audited.

    The original title contains a warning contrast worth noting: the prompt layer says “do not execute,” while the configuration file layer says “execution is welcome.” Natural-language prompts are soft constraints, whereas configuration registration, tool discovery, dependency installation, and command execution are hard paths. As long as the Agent can modify global configuration or register external tools after reading project instructions, “do not” in a prompt is unlikely to become a security boundary. Effective boundaries should sit in execution policy, configuration integrity, outbound network control, and credential management.

    Below, rather than retelling a specific attack, we abstract the chain into five executable checks: entry points, configuration integrity, separation of prompts and execution, outbound allowlisting, and rotation on discovery.

    2. Abstract Model of the Attack Chain

    A typical configuration injection chain can be abstracted into five actions:

    1. File drops to disk: a web page or external content writes a project instruction file into a user-writable directory, especially the downloads directory. In many desktop environments, downloads is one of the locations where external content can be written with relatively low interaction cost.
    2. Wrong workspace launch: the user starts a coding Agent in the downloads directory, a temporary directory, or another untrusted directory, and the Agent treats the current directory as the project root.
    3. Instruction file is trusted: the Agent reads the project-level instruction file and incorporates its “engineering standards,” “local development environment,” and similar content into the system prompt or execution plan.
    4. Global configuration is rewritten: a small passage in a long document induces the Agent to append global configuration, register an external tool service, modify startup commands, or change default behavior.
    5. Later execution is triggered: in the next task, the Agent pulls a dependency package or calls an external service according to the new configuration, completing malicious code execution.

    Each step corresponds to a checkable location. Security teams do not need to wait for vendor patches; instead, they should turn “is the current directory trusted,” “has global configuration drifted,” “can project files rewrite global configuration,” “are dependency downloads controlled,” and “are credentials rotated after discovery” into pipeline gates.

    3. Check 1: Entry-Point Control — First Answer “In Which Directory Did the Agent Start?”

    The core of entry-point detection is not identifying a particular filename, but identifying “untrusted workspaces.” Project-level instruction files are a reasonable mechanism; the problem is that the Agent treats files in downloads, temporary, or shared directories as trusted project standards.

    Recommended controls include at least the following:

    • Working directory allowlist: coding Agents are allowed to start only in a version-controlled repository root, a managed project directory, or an explicitly registered workspace; downloads, desktop, and temporary directories are denied by default.
    • First-use trust confirmation: when starting in a non-allowlisted directory, force display of the directory source, file list, instruction file hashes, and configuration items to be loaded, and require manual confirmation.
    • Source tagging: add source tags to files downloaded from browsers, received as email attachments, or received via chat tools; when the Agent reads instruction files with external source tags, downgrade or reject them.
    • File type and content checks: perform static scanning of project instruction files for size, encoding, suspicious path references, configuration-write instructions, and external-tool registration keywords.
    • Session isolation: Agent sessions in untrusted workspaces should disable global configuration writes, dependency installation, and external tool registration by default.

    Entry control cannot rely only on “reminding users not to do this.” Report materials often note that a significant share of users run tools in the downloads directory, and many sessions open a real browser. This means habit itself is an attack surface. Gates should block by default, not rely on user discipline.

    4. Check 2: Configuration Integrity — Global Configuration Must Be Baselinable, Auditable, and Reversible

    The key step in configuration injection is that project files induce the Agent to modify global configuration. Configuration integrity detection should therefore answer three questions: what changed, who allowed it, and can it be rolled back?

    Actionable controls include:

    1. Establish a configuration baseline: create a file inventory, hashes, and a snapshot of key fields for the global configuration directory to form a read-only baseline. Compare it before and after each Agent session.
    2. Key-field allowlist: in global configuration, fields related to external tool registration, startup commands, environment variables, package sources, proxies, and credential paths must not be modified automatically by project-level instructions.
    3. Change approval: any global configuration write must go through an independent policy engine or manual approval; project instruction files can only make suggestions, not take effect directly.
    4. Read-only mounts and permission isolation: in a container or sandbox, mount the global configuration directory read-only; when changes are needed, submit them through a controlled interface.
    5. Signature and source verification: verify managed configuration with signatures or hash manifests; unsigned changes go to an isolation area.
    6. Audit logs: record the session ID, working directory, triggering file, before/after diff, and executed commands for configuration changes; connect them to log services and monitoring alerts.

    The value of configuration integrity detection is that it does not depend on identifying a particular attack sample. Whether the attack hides in a “local development environment” subsection or disguises itself as “toolchain initialization,” as long as it causes global configuration to add an external tool registration entry or an abnormal startup command, it produces detectable drift.

    5. Check 3: Prompt/Execution Separation — Natural-Language Constraints Cannot Replace a Policy Engine

    The contrast “the prompt says do not execute, while the configuration file says execution is welcome” exposes a layer mismatch. Natural-language prompts are model input; configuration registration is execution-policy input. The security boundary must sit at a lower layer.

    A layered model is recommended:

    • Prompt layer: project instruction files describe only business standards, code style, and test requirements; they must not contain instructions for global configuration writes, external tool registration, package source changes, or credential reads.
    • Policy layer: an independent policy engine decides which directories the Agent can read and write, which tools it can call, whether it can install dependencies, and whether it can access the network. The policy layer does not read natural-language authorization in project instruction files.
    • Execution layer: command execution, dependency installation, and external tool calls all run in a sandbox, with no network or only allowlisted network by default, and no global configuration write permission by default.
    • Audit layer: raise a separate alert for events where “a project instruction file attempts to modify configuration,” rather than only logging ordinary file reads.

    A practical rule is: project-level instruction files must never elevate privileges. They can suggest a test command, but they cannot register a new external tool service; they can describe code standards, but they cannot modify the global default model, proxy, package source, or credential path. If the business genuinely needs project-level configuration, it should be done through controlled project configuration file templates and an approval process, not by letting the Agent freely append global configuration.

    6. Check 4: Outbound Allowlisting — Block Malicious Dependency Pulls at the Network Layer

    The ultimate goal of configuration injection is usually code execution. Code execution needs a delivery vehicle, commonly a dependency package, script, external tool service, or remote command. Network outbound allowlisting is the last high-value line of defense.

    Recommended controls:

    • Deny outbound by default: the Agent sandbox has no internet by default and can access only managed package sources, internal artifact repositories, and necessary APIs.
    • Authorize per task: a task opens only a minimal allowlist of domains, ports, and protocols; the allowlist is revoked when the task ends.
    • Lock package sources: dependency installation may use only lock files and trusted artifact repositories; runtime switching of package sources or use of unknown sources is prohibited.
    • Dependency integrity verification: verify package hashes, signatures, and provenance; new dependencies must be approved.
    • External tool service allowlist: only reviewed external tool service addresses and command templates may be registered; dynamic appends by project files are prohibited.
    • Dual control of DNS and IP: enforce domain allowlists and also restrict resolution results and direct IP connections to prevent bypass.
    • Alert integration: trigger alerts for first-seen outbound destinations, abnormally high-frequency downloads, and dependency installation outside working hours.

    If your team uses a centralized log service and monitoring/alerting platform, you can bring Agent sandbox outbound-block events, configuration drift events, and dependency installation events into a unified audit view for cross-session tracking. The core, however, remains the policy itself: without an allowlist, detection can only find issues after the fact; with an allowlist, even if malicious dependencies are written into configuration, downloading and executing them is difficult.

    7. Check 5: Rotate on Discovery — Response Rules Must Be Written into the Playbook

    When a project instruction file is found to induce configuration changes, do not just delete the file. Treat it as “possibly already executed”:

    1. Isolate the session and host: pause the relevant Agent session, preserve evidence, and isolate the affected workspace.
    2. Rotate credentials: rotate code repository tokens, package source tokens, cloud access keys, and external tool service credentials accessible to that session.
    3. Clean up persistence items: check global configuration, startup items, external tool registrations, environment variables, proxy settings, package source configuration, and cache directories.
    4. Audit historical sessions: trace all sessions and outbound connections within the same working directory and the same configuration change time window.
    5. Reproduce and codify gates: turn samples into entry detection, configuration drift detection, and outbound alert rules, and add them to regression tests.
    6. Notify and review: notify relevant parties according to internal security procedures, and review why an untrusted directory could start the Agent and why global configuration could be modified by project files.

    “Rotate on discovery” is not an overreaction; configuration injection may already have changed later execution paths. If credentials are not rotated, cleanup is incomplete.

    8. Example Configuration Drift Check Script

    The following pseudocode example aims to check file inventory, hashes, and key field changes in the global configuration directory before and after an Agent session. In practice, replace it with your team’s configuration format and audit interfaces.

    1. # Configuration drift check pseudocode
    2. INPUT:
    3. baseline_manifest # Baseline: file path -> hash, key field snapshot
    4. global_config_dir # Global configuration directory
    5. session_id
    6. workspace_dir
    7. FUNCTION scan_config(dir):
    8. files = []
    9. FOR file IN walk(dir):
    10. files.append({
    11. path: relative_path(file),
    12. hash: sha256(read_bytes(file)),
    13. size: file_size(file)
    14. })
    15. RETURN files
    16. FUNCTION extract_risk_fields(config_files):
    17. risks = []
    18. FOR file IN config_files:
    19. content = read_text(file)
    20. IF content CONTAINS "external_tools" OR
    21. content CONTAINS "startup_command" OR
    22. content CONTAINS "package_source" OR
    23. content CONTAINS "proxy" OR
    24. content CONTAINS "credential_path":
    25. risks.append({
    26. file: file,
    27. risk: "sensitive_config_field_present"
    28. })
    29. IF content CONTAINS workspace_dir OR
    30. content CONTAINS "download" OR
    31. content CONTAINS "tmp":
    32. risks.append({
    33. file: file,
    34. risk: "untrusted_workspace_reference"
    35. })
    36. RETURN risks
    37. FUNCTION main():
    38. current = scan_config(global_config_dir)
    39. diff = compare(baseline_manifest.files, current)
    40. IF diff.added OR diff.removed OR diff.modified:
    41. alert("CONFIG_DRIFT", {
    42. session_id: session_id,
    43. workspace_dir: workspace_dir,
    44. diff: diff
    45. })
    46. risk_fields = extract_risk_fields(current)
    47. IF risk_fields NOT EMPTY:
    48. alert("SENSITIVE_CONFIG_CHANGE", {
    49. session_id: session_id,
    50. risks: risk_fields
    51. })
    52. IF workspace_dir MATCHES "download|tmp|desktop|shared":
    53. alert("UNTRUSTED_WORKSPACE_START", {
    54. session_id: session_id,
    55. workspace_dir: workspace_dir
    56. })

    The key to the script is not complexity but executability: baseline first, comparison before and after the session, separate alerts for sensitive fields, and alerts on untrusted workspace starts. Connect the script to CI/local hooks/sandbox launchers and write alerts to a unified log service.

    9. Control Matrix

    Control area Detection point Recommended policy Failure action
    Entry Agent starts in a non-allowlisted directory Working directory allowlist; first-use trust confirmation Block or downgrade the session
    Entry Instruction file from an external source Source tagging; static content scanning Reject loading and alert
    Configuration integrity Global configuration adds an external tool registration entry Baseline hashes; key-field allowlist Roll back and require approval
    Configuration integrity Project file references global configuration paths Rule scanning; write permission isolation Block the write
    Prompt/execution separation Project instruction requests dependency installation Independent authorization by policy engine Deny by default
    Prompt/execution separation Project instruction requests package source/proxy changes Prohibit project-level privilege elevation Alert and isolate
    Outbound allowlist Outbound to unknown domain or IP Deny by default; authorize per task Block the connection
    Outbound allowlist Download from an untrusted package source Artifact repository locking; hash verification Reject installation
    Response Configuration drift discovered Isolate, rotate, audit, review Enter the security incident process

    10. Conclusion: Turn “Unpatchable” into “Gated”

    This risk is difficult because Agent reading workspace instructions, merging configuration, and calling tools are all by-design behaviors. It is unrealistic to expect a prompt saying “do not execute” to block configuration injection. Engineering teams should push security boundaries down to five layers: entry, configuration, policy, network, and response. Do not let untrusted directories easily become project roots; do not let project files rewrite global configuration; do not let natural-language prompts replace execution policy; do not let unknown dependencies go outbound freely; and do not let a discovery end with deleting a file.

    When these checks become default gates, configuration injection is no longer an incidental question of “whether a tool can be fooled,” but an engineering problem that is detectable, blockable, and auditable.