Using AI agents is accelerating feature implementation but also requires greater attention to how security requirements are defined, applied, and verified.

An agent may develop an operationally correct feature yet introduce vulnerabilities such as authorization failures, data exposure, insufficient validation, or insecure dependencies.

The problem does not necessarily lie in the model's ability to understand security, but in missing specific requirements, appropriate context, and validation mechanisms ensuring consistent application.

The strategy is incorporating security into development, using agents to analyze threats, implement solutions, and investigate problems, with policies, contracts, and checks guiding work from planning to delivery.

1. Security in AI development

When agents produce code quickly, vulnerabilities may be introduced in different modules before detection.

A problem can also be reproduced across several implementations when agents receive no guidance on existing security mechanisms.

For example, an agent may create a functional endpoint using authentication but not check whether the user has permission to access the requested resource.

Functional tests may pass while the vulnerability remains.

A more efficient approach combines three responsibilities:

  • Prevention: establish requirements and constraints guiding implementation.
  • Detection: identify vulnerabilities through tests, analysis, and specialized tools.
  • Correction: resolve identified problems and incorporate mechanisms preventing recurrence.

These activities should belong to normal development flow, with depth proportional to each change's impact.

2. Security requirements as part of context

Like architectural decisions and API contracts, security requirements need to be available in project context.

Generically instructing an agent to develop secure code is not enough.

The project should indicate existing mechanisms, rules requiring respect, and operations needing specific controls.

This information can be organized in AGENTS.md, CHAOS, or equivalent structures, referencing more specific documents.

Depending on the application, context may include:

  • Authentication and session management mechanisms.
  • Authorization and access control standards.
  • Isolation rules between organizations or users.
  • Input validation and handling.
  • Data storage and exposure policies.
  • Credential and sensitive information handling.
  • Approved security libraries and mechanisms.
  • External integration restrictions.
  • Review and validation procedures.

Operational instructions, not just recommendations

An instruction such as "check user permissions" may be insufficient when the project has specific authorization mechanisms.

It is more useful to indicate which service, middleware, or policy to use and where corresponding contracts are defined.

The same applies to authentication, data validation, and error handling.

The agent should know and reuse existing security controls instead of improvising parallel solutions.

When an implementation requires changing these mechanisms, the decision should follow the project's established approval process.

3. Threat analysis before implementation

AI agents can assist risk identification before code is produced.

Threat analysis assesses how a feature may be misused, which resources need protection, and where trust boundaries exist.

This analysis should consider application architecture and data flows.

Relevant aspects include:

  • Feature entry points.
  • Received and processed data.
  • Available resources and operations.
  • Identities and permissions involved.
  • Other service integrations.
  • Trust boundaries between components.
  • Possible abuse scenarios.

For example, when implementing document sharing, defining how users upload and access files is insufficient.

You need to assess who can view documents, how permissions are revoked, which metadata is exposed, and how to prevent access to other users' files.

An agent can help identify these scenarios and propose controls using requirements and existing architecture as references.

Analysis proportional to risk

An isolated visual modification is unlikely to require the same effort as a new authentication mechanism or feature processing sensitive information.

Analysis depth should consider feature criticality, external exposure, data involved, and consequences of potential failure.

Threat analysis should guide implementation and security decisions, not become a formality disconnected from actual risks.

4. Authentication and session management

Agents implementing authenticated features should reuse existing project mechanisms.

Creating parallel authentication solutions may introduce inconsistencies in session management, token validation, expiration, and access revocation.

Technical context should indicate how the application handles:

  • User identification and authentication.
  • Tokens and sessions.
  • Cookies and their security attributes.
  • Credential expiration and renewal.
  • Session revocation.
  • Account recovery.
  • Identity provider integration.

Avoiding improvised mechanisms

When the project already has authentication libraries, services, and middleware, the agent should use them according to existing contracts.

Changes to these mechanisms require special attention because they may affect multiple features.

Review should consider not just whether login works but whether implementation respects session, expiration, and credential protection policies.

These mechanisms should remain consistent across application modules.

5. Authorization and data isolation

Authentication confirms user identity but does not determine which resources they can access.

Authorization failures deserve special attention in agent-developed applications, particularly when endpoints are implemented individually.

Consider an order query API:

GET /api/orders/123

The user may be correctly authenticated, but this does not guarantee order 123 belongs to them or their organization.

Authorization should be applied in the backend, respecting system rules.

Multi-tenant applications

In systems serving multiple organizations, data isolation is especially important.

An agent may correctly implement an organization filter in one query and forget the same control in another operation.

This can happen in:

  • Record queries.
  • Updates and deletions.
  • Data exports.
  • Reports and aggregations.
  • Background processing.
  • Administrative operations.
  • File and document access.

The strategy should prioritize shared authorization and isolation mechanisms, reducing the need to implement checks separately in every endpoint.

Whenever possible, reinforce these rules through contracts, access policies, and automated tests.

Unauthorized access tests

Besides checking whether an authorized user can access a resource, validate that users lacking permission are blocked.

In multi-tenant systems, tests should consider cross-organization access attempts.

Authorization needs checking per operation and resource, not just through the existence of an authenticated session.

6. Input validation and API security

Agents may implement APIs that work correctly with expected inputs but do not account for invalid values or malicious behavior.

Validation should therefore follow project-defined contracts and mechanisms.

Whenever possible, use existing schemas and libraries instead of creating independent validation for every endpoint.

Checks may involve:

  • Data types and formats.
  • Size and quantity limits.
  • Required and optional fields.
  • Allowed values.
  • Nested structures.
  • Query parameters.
  • Data received from external integrations.

Also consider how information is used after validation.

Validating types does not replace parameterized queries, appropriate output encoding, or other controls specific to the data destination.

Responses and error handling

API security also depends on returned information.

Agents should respect data exposure rules, avoiding internal properties, credentials, sensitive information, or unnecessary details in responses.

Error messages should not reveal internal information facilitating attacks, such as database structures, sensitive paths, or configuration secrets.

Project context should identify existing serialization, error handling, and exposed data control mechanisms.

7. Dependencies and third-party code

AI agents may add libraries for problems already solved in the project or addressable with existing resources.

Besides increasing complexity, new dependencies introduce maintenance and security risks.

Before adding a package, the agent should check:

  • Whether a solution is available in the project.
  • Whether the dependency is actually necessary.
  • Whether the package has adequate maintenance.
  • Whether known vulnerabilities exist.
  • Whether transitive dependencies introduce risks.
  • Whether the license is compatible with the project.

The process should also consider installed package versions and integrity.

Lockfiles and dependency verification mechanisms help maintain reproducible installations.

Supply chain analysis

Software Composition Analysis (SCA) tools can identify known vulnerabilities and problematic dependencies.

These checks should belong to automated flow whenever possible.

However, alerts need evaluation according to the version used, exploitability, and actual application exposure.

Not every reported vulnerability represents the same risk level.

Implementation speed should not cause uncontrolled expansion of dependencies and attack surface.

8. Secrets and sensitive information

Agents may access configuration files, logs, API responses, and other resources containing sensitive information.

These data should not be incorporated into code, exposed in responses, or unnecessarily recorded during execution.

The project should establish clear credential and confidential information usage rules.

This includes:

  • Do not store secrets directly in code.
  • Use appropriate credential management mechanisms.
  • Separate configuration by environment.
  • Avoid token exposure in logs.
  • Restrict access permissions.
  • Do not include sensitive data in evidence or reports.
  • Use fictitious or anonymized data when appropriate.

It is also important to control information made available to model context.

An agent does not need a credential's contents to know how to configure an integration.

Whenever possible, secrets should be used through execution environment mechanisms without exposing their values directly to the model.

Production credentials

Operations involving production environments require additional controls.

Even when the agent runs in an isolated environment, broadly privileged credentials may allow external service changes.

Operational isolation and access control therefore need joint application.

9. Automated security analysis

A significant share of security checks can be performed by specialized tools.

These tools should be integrated into development and CI/CD pipelines to consistently identify known problems.

Check Purpose
SAST Identify potentially vulnerable source code patterns
SCA Analyze dependencies and known vulnerabilities
Secret scanning Detect potential credentials and sensitive information
DAST Evaluate security behavior in running applications
Contract validation Identify interface and data structure incompatibilities
Infrastructure analysis Check configuration and security policies

These tools have limitations and may produce false positives or miss certain problems.

Nevertheless, they provide an important foundation for recurring detection and can prevent known problems from reaching later stages.

AI's role

Agents can interpret results, investigate vulnerabilities, assess finding impact, and propose corrections.

They can also help configure rules and develop project-specific checks.

Specialized tools thus run recurring analysis while agents investigate results requiring technical context.

10. Security reviewer agents

Automated tools do not necessarily identify failures related to business logic, authorization, or interactions among components.

Reviewer agents can complement these checks by analyzing implementation in application context.

For example, an agent can verify whether an administrative feature respects existing permissions or whether an operation allows access to another organization's resources.

These analyses need to consider:

  • Project security requirements.
  • Architecture and trust boundaries.
  • Contracts and authorization policies.
  • Changed code and related components.
  • Automated check results.

Contextual investigation

A reviewer agent's main value is connecting information a traditional tool may assess in isolation.

A database query can be correctly parameterized yet allow unauthorized access to another organization's records.

Likewise, an endpoint can meet input and output contracts but perform an operation requiring additional permissions.

These problems depend on understanding rules and component relationships.

Verifiable findings

Reviewer agents can also produce false positives.

Recommendations should therefore present the identified problem, affected resource, impact, and technical rationale.

When possible, a finding should include a reproducible scenario or reference allowing vulnerability confirmation.

Risk identification should not automatically produce changes without evaluation.

AI can expand investigation capacity, but conclusions need substantiation and verification.

11. Risk-oriented security tests

Besides code and dependency analysis, security requirements need verification in application behavior.

Agents can assist in creating tests reproducing unauthorized access, feature abuse, and isolation failures.

These tests should join the project suite for execution during future changes.

Some examples include:

  • Access attempts without authentication.
  • Resource access without authorization.
  • Operations across different organizations.
  • Invalid or unexpected inputs.
  • Improper property exposure.
  • Session and expiration behavior.
  • Administrative operation restrictions.
  • External integration failures.

Example: isolation between organizations

In a multi-tenant application, a test can create resources associated with two different organizations.

Validation should confirm that a user from organization A cannot query, modify, or delete resources belonging to organization B.

This scenario can run automatically whenever changes affect the modules involved.

A critical rule thus gains an objective, reusable check.

Vulnerability fixes

Whenever possible, an identified vulnerability should produce a test reproducing the problem.

The test should demonstrate failure in the vulnerable implementation and pass after correction.

This helps prevent future changes from reintroducing the same insecure behavior.

Security tests should run in controlled environments, respecting project-established permissions and limits.

12. Security as a delivery criterion

Implementation approval needs to consider security requirements applicable to the change.

The process should define mandatory checks, which problems prevent integration, and when an additional decision is necessary.

One possible classification:

Low-risk changes

Can use existing automated checks and conventional review.

Changes affecting security

May require specific tests, contract analysis, and targeted review.

Critical changes

May justify threat analysis, specialist review, and additional approval.

Blocking criteria

Confirmed high-severity vulnerabilities, mandatory policy violations, and significant authorization failures normally need resolution before approval.

Other findings may require investigation, mitigation, or formal risk acceptance according to team policies.

Decisions should consider severity, exposure, exploitability, and problem impact.

Evidence

Delivery should provide information necessary to demonstrate required checks were performed.

This may include test results, automated analyses, and rationale for relevant security decisions.

Evidence should reveal which controls were checked and which risks remain without excessive documentation for simple changes.

13. Learning and updating instructions

A vulnerability found during development is an opportunity to improve project prevention mechanisms.

If different agents reproduce the same problem, the cause may be incomplete instructions, missing tests, or insufficient architectural mechanisms.

Correction should consider not only affected code but also the process that allowed the vulnerability's introduction.

Depending on the case, this may result in:

  • Updated security instructions.
  • Revised contracts and policies.
  • Regression test creation.
  • Additional automated checks.
  • Improved shared services or middleware.
  • Updated specific skills and procedures.

For example, if agents frequently forget authorization checks in new endpoints, correcting each occurrence alone may be insufficient.

A shared mechanism applying these rules consistently may be needed, along with updated context guiding its use.

Context maintenance

Security instructions should evolve alongside architecture and code.

When implementation changes authentication, authorization, or data handling mechanisms, corresponding documents need review.

An AGENTS.md rule can require checking each change's technical context impact and updating affected references before task completion.

This reduces the chance of future agents using instructions incompatible with current system state.

Improvements should be incorporated into the project so the same problem does not need repeated rediscovery and correction.

Conclusion

Security in development with AI agents needs incorporation into project technical context and validation mechanisms.

Well-defined requirements guide implementations, while specialized tools, automated tests, and contextual reviews help identify vulnerabilities before delivery.

When problems are found, fixes should also improve controls and instructions used in subsequent implementations.

The goal is to benefit from agent speed without compromising security, making requirements and protection mechanisms a permanent, verifiable part of development.

Sources and further reading