# Secure Agents

Use the agent security workflow to harden a deployed application agent before
promotion. The workflow checks whether model traffic is routed through
guardrails, samples recent telemetry for sensitive data, and writes actionable
suggestions that can be reviewed alongside optimization suggestions.

## What the Security Workflow Checks

| Suggestion type | Signal | Result |
|-----------------|--------|--------|
| Guardrails | Agent LLMs call an unguarded model endpoint | Suggests creating a guarded virtual model and pointing the agent at it |
| Data safety | Recent telemetry contains likely PII or leaked secrets | Suggests redaction or regeneration and immediate credential rotation for secrets |
| Deep scan | Regex scanning is not enough for the data risk profile | Suggests running higher-recall GLiNER or NemoGuard model checks on a subset of traces |

Security state is stored separately from optimization state:

- `nemo-agent-security/security_snapshot.json`
- `nemo-agent-security/security_suggestions.jsonl`

## Prerequisites

Before running security checks, make sure you have:

1. Local services running with `nemo setup` or `nemo services run`.
1. At least one deployed platform-managed agent.
1. A model provider and model entities registered in the workspace.
1. Optional telemetry in the `nemo-agent-telemetry` fileset if you want data
   safety suggestions.

If you accepted **Install skills** during setup, ask your coding agent to help
secure the agent. The skill inspects the selected agent, checks guardrail
coverage, samples telemetry, and writes suggestions to platform files.

```bash
nemo agents list
```

## Add Guardrails to the Model Path

Guardrails are attached through virtual models. A guarded virtual model keeps
the application agent config stable while adding request or response checks in
the model path.

```bash
nemo inference virtual-models create guarded-agent-model \
  --workspace default \
  --models '[{"model":"default/<backend-model-entity>","backend_format":"OPENAI_CHAT"}]' \
  --request-middleware '[{
    "name":"nemo-guardrails",
    "config_type":"guardrail_config",
    "config_id":"default/<guardrail-config>"
  }]' \
  --response-middleware '[{
    "name":"nemo-guardrails",
    "config_type":"guardrail_config",
    "config_id":"default/<guardrail-config>"
  }]'
```

After creating the virtual model, deploy a candidate agent that uses the guarded
model entity, run evaluation, and compare against the baseline before
promotion.

## Scan Telemetry for Sensitive Data

The security skill samples recent telemetry from `nemo-agent-telemetry` and
looks for high-confidence patterns such as email addresses, SSNs, phone numbers,
credit cards, private keys, JWTs, and common model-provider API keys. Findings
are written with masked previews, file locations, and follow-up actions.

For leaked secrets, rotate the credential before doing any other cleanup. For
PII in trace data, redact or regenerate affected traces before using them for
evaluation or optimization.

## Review Results

Use the Files service to inspect saved suggestions:

```bash
nemo files list --fileset nemo-agent-security

nemo files download \
  --fileset nemo-agent-security \
  --remote-path security_suggestions.jsonl \
  -o security_suggestions.jsonl
```

## Next Steps

- [Optimize Agents](optimization.md): reduce cost and improve quality after
  security coverage is in place.
- [Guardrails](../guardrails/index.md): create and manage guardrail
  configurations.
- [Models and Inference](../run-inference/about.md): manage model providers,
  model entities, and virtual models.
