AI coding assistants usually arrive in an organisation before any policy does, and by the time security is asked to approve them developers are already sending source code to model providers, accepting agent edits to pipelines and connecting tools that run with their own credentials. This playbook covers rolling out an AI coding assistant as a product class, from inline completion to agent modes that run commands: the design decisions to make first, how to configure the platform and developer environments, how to pilot and expand by risk tier, how to test and roll back, and what to measure. It is vendor-neutral and based on the OWASP Secure Coding with AI Cheat Sheet, the OpenSSF Security-Focused Guide for AI Code Assistant Instructions, NIST SP 800-218A, the OWASP Top 10 for LLM Applications 2025 and NIST SP 800-53 Rev. 5. It is written for engineering leaders, platform teams and application security. Threats to the IDE and agent are covered in the AI IDE and Coding Agent Security Guide; selection is covered in the AI Coding Assistant Buyer's Guide; the general enterprise copilot rollout is covered in the Enterprise AI Copilot Security Guide.
Key takeaways
- Roll out by capability tier, not by team. Inline completion, chat, agent mode in the IDE and agents in CI carry very different risks; approve each tier separately with its own controls.
- Know what context leaves the laptop. OWASP notes the context sent to the provider often includes more than the current file, and that version control ignore files do not stop AI tools reading the file system. Configure the tool's own exclusions before the pilot.
- Review processes do not change because the author is a model. OpenSSF and OWASP both say AI-generated code still goes through code review, testing and static analysis, with a named human owner for every change.
- Repository instruction and rules files are security configuration. They steer the agent and can be written by attackers; require review for every change.
- Agents need a sandbox and a credential boundary. Run agent modes in containers or ephemeral workspaces with tool allowlists and egress limits, away from production credentials.
Phase 0: design decisions
| Decision | Options | Security built in |
|---|---|---|
| Deployment and data handling | Hosted service under an enterprise agreement, private cloud deployment, or self-hosted model | Source code sent for inference is a transfer to an external service (SA-9): confirm retention, training use, region and sub-processors in the contract. OWASP suggests self-hosted or air-gapped tools for classified, regulated or highly sensitive code |
| Capability tiers enabled | Completion, chat, IDE agent mode, command-line agent, CI or review agent | Enable tiers deliberately; each higher tier adds tool use and command execution (OWASP LLM06 Excessive Agency) |
| Identity and licensing | Seats assigned through the identity provider, or individual sign-up | Single sign-on and group-based assignment so leavers lose access and personal accounts are blocked |
| Repository scope | All repositories, or allowlisted repositories by classification | Exclude repositories holding regulated data, cryptographic material or security tooling until reviewed |
| Tool and connector policy | No external tools, an approved list, or open | OWASP: allowlist approved MCP servers and tools, snapshot and diff tool definitions. See the MCP Gateway and MCP Server Governance Guide |
| Telemetry and audit | Provider admin logs only, or export to the SIEM | Record which developer approved which AI-generated change, with tool and model version (OWASP) |
| Acceptable use | Policy covering data, code ownership and licences | Publish before the pilot. Start from the AI Acceptable Use Policy Template |
Capability tiers and the controls each needs
| Tier | What it can do | Minimum controls before enabling |
|---|---|---|
| 1. Inline completion | Suggests code in the editor | Context exclusions, enterprise data terms, normal review and scanning |
| 2. Chat | Answers questions using files and selected context | Tier 1 plus guidance not to paste secrets or customer data |
| 3. IDE agent mode | Edits many files, runs terminal commands, calls tools | Tier 2 plus command approval prompts kept on, tool allowlist, rules-file review, no production credentials on the workstation |
| 4. Autonomous or command-line agent | Runs multi-step tasks with fewer prompts | Tier 3 plus a sandbox (dev container, VM or ephemeral workspace), egress limits, task-scoped credentials |
| 5. CI and review agents | Comment on or push to pull requests from a pipeline | Least-privilege pipeline token, approval gate before pushing commits or changing workflows, no secrets exposed to review bots (OWASP) |
Phase 1: configure the platform and developer environment
- Connect to the identity provider: single sign-on with MFA, seats assigned by group, personal or unmanaged accounts blocked at the network or browser where possible.
- Set organisation policies centrally: enabled tiers, allowed models, public code matching or licence filters if the product offers them, and data retention settings, locked so individual users cannot override them.
- Configure context exclusions: use the tool's own ignore mechanism to exclude environment files, private keys, credential files and sensitive directories. OWASP warns that version control ignore files only affect git.
- Move secrets out of the project tree: OWASP advises keeping secrets in vault services rather than the working directory, avoiding opening environment files while an assistant is active, and using ephemeral, task-scoped credentials. See the How to audit AI coding assistant tokens and config files guide.
- Publish a baseline instructions file: the OpenSSF guide recommends repository instructions that tell the assistant to validate input, use parameterised queries, never hard-code secrets, prefer well-vetted dependencies with pinned versions and generate security tests. Keep it short, specific and reviewed.
- Prepare agent sandboxes: a standard dev container or ephemeral workspace image with no cloud CLI profiles, SSH keys or production access, and egress limited to the package registries and source control the task needs. See the AI Agent Sandboxing and Code Execution Guide.
- Manage extensions: deploy the assistant's extension or binary through managed software distribution with version pinning, so a malicious update can be held back. The coding assistant extension compromise showed injected instructions shipping in an official release.
Phase 2: guardrails in the delivery pipeline
The assistant changes how code is written; the pipeline decides what ships. Put these in place before expanding past the pilot, because they apply equally to human and AI-written code (PR.PS-06, SA-11, SA-15):
- Branch protection and human approval: every change, including agent pull requests, needs approval from a person who is not its requester. OWASP: review the full diff, because agents modify lockfiles, CI configuration and tests that summaries omit.
- Static analysis and secret scanning on every pull request: with push protection for secrets. See the Git Secret Scanning Guide.
- Dependency checks: OWASP recommends verifying that suggested packages exist and are established, enforcing a minimum package age and an internal allowlist, and failing builds on known vulnerabilities. Hallucinated package names are registered by attackers (slopsquatting). See the Malicious Package and Dependency Confusion Guide; the TrapDoor supply chain campaign targeted developers using AI assistants with malicious packages.
- Protected paths: changes to instruction and rules files, CI workflow definitions and code ownership files require security review and raise an alert. See Coding Agent Configuration File Attacks.
- Test integrity checks: flag deleted tests, weakened assertions and new mocks in AI-assisted changes; OWASP lists test fabrication as a review concern.
Phase 3: pilot
Pick 20 to 50 developers across two or three teams with different languages and risk levels (our recommendation), on tiers 1 and 2 only. Run for four to six weeks. Collect: what context the tool actually sends (OWASP suggests controlled request inspection with credentials redacted), false positives from exclusions, pipeline findings in AI-assisted changes compared with the baseline, and developer feedback on the instructions file. Exit criteria: exclusions verified, pipeline guardrails live, policy acknowledged by every pilot user, and no unresolved data handling questions from legal or privacy.
Phase 4: expansion waves
- Wave 1, tiers 1 and 2 for all developers on allowlisted repositories, after the pilot exit criteria are met.
- Wave 2, tier 3 IDE agent mode for teams that complete short training on approval prompts, rules-file risks and tool allowlists, with the approved MCP server list enforced. See How to audit MCP servers on developer laptops.
- Wave 3, tier 4 agents in sandboxes for defined task types such as dependency upgrades, test generation and refactoring, with task-scoped credentials only.
- Wave 4, tier 5 CI and review agents on selected repositories, with pipeline tokens limited to commenting or opening pull requests and an approval gate for any push or workflow change.
- Wave 5, sensitive repositories: only after a separate review, possibly with a self-hosted or private deployment.
Testing and rollback
- Test before each wave: plant canary secrets and a decoy sensitive file in a test repository and confirm the exclusions keep them out of context; open a repository containing a hostile instructions file and confirm approval prompts and the tool allowlist stop the actions it asks for.
- Rollback levers: disable a tier centrally in the organisation policy, remove seats by group, block an extension version through software distribution, and revoke the CI agent's pipeline token. Practise each once before production use.
- Code rollback: because every AI-assisted change carries an owner and an audit record, changes from a compromised tool version can be found and reverted.
Small versus large organisations
- Small teams: one hosted product under business terms, tiers 1 to 3, a shared instructions file, and pipeline guardrails from the source control platform. Skip CI agents until branch protection and secret scanning are mature.
- Large estates: a central platform team owns the policy, sandbox images, approved tool list and instructions baseline; business units opt in by tier; application security tracks findings in AI-assisted changes.
- Regulated environments: data residency and no-training terms in the contract, a private or self-hosted model for sensitive repositories, and evidence of review for every AI-generated change mapped to NIST SP 800-218A. See the NIST SP 800-218A SSDF Community Profile for Generative AI Guide.
Where identity fits
An agent mode acts with whatever credentials the developer's session holds: source control tokens, cloud CLI profiles, package registry tokens and SSH keys. OWASP advises blocking agent access to credential stores, SSH keys and cloud CLI configurations, and preventing sub-agents from inheriting the parent's full permissions. In CI, the agent is a non-human identity in its own right: give it a dedicated, least-privilege token with an owner and expiry, not a shared bot account. The malicious repository MCP configuration flaw showed how opening a hostile repository can expose a developer's cloud credentials through the assistant. See the AI Coding Agents Security Guide.
Detection and measurement
Monitor: changes to instruction, rules and workflow files; new or changed MCP server configurations on managed devices; agent processes reading credential files or calling cloud CLIs; outbound connections from sandboxes outside the egress allowlist; installation of very new or low-download packages; and admin policy changes in the assistant platform.
| Metric | How to measure | Target (our recommendation) |
|---|---|---|
| Managed adoption | Developers using the assistant through enterprise seats, divided by developers using any assistant (from network and endpoint data) | Rising towards 100% |
| Change ownership | AI-assisted pull requests with a named human approver | 100% |
| Pipeline findings | Static analysis and secret findings per 100 AI-assisted pull requests compared with the baseline | Not higher than the baseline |
| Unreviewed rules changes | Changes to instruction, rules or workflow files merged without security review | Zero |
| Unapproved tools | MCP servers or extensions found on managed devices outside the approved list | Falling to zero |
| Credential exposure in sandboxes | Long-lived credentials found in agent sandbox images or workspaces | Zero |
Framework mapping
| Rollout element | NIST SP 800-53 Rev. 5 | NIST CSF 2.0 | Threat reference |
|---|---|---|---|
| Provider contract and data handling | SA-9 External System Services | GV.SC-07 | OWASP LLM02 |
| Capability tiers and tool allowlists | CM-7 Least Functionality, AC-6 Least Privilege | PR.AA-05, PR.PS-01 | OWASP LLM06; ATLAS AML.T0053 AI Agent Tool Invocation |
| Review, testing and scanning | SA-11 Developer Testing and Evaluation, SA-15 | PR.PS-06 | OWASP LLM05 Improper Output Handling |
| Dependencies and extensions | SR-3 Supply Chain Controls and Processes | GV.SC-07 | ATT&CK T1195.002; OWASP LLM03 |
| Rules files and repository content | CM-3 Configuration Change Control | PR.PS-01 | ATT&CK T1698 Indirect Prompt Injection |
| Credentials on workstations | IA-5(7), AC-6 | PR.AA-01 | ATT&CK T1552.001 |
| Audit of AI-assisted changes | AU-2 Event Logging, SI-4 | PR.PS-04, DE.CM-09 |
Common failure patterns
- Agent mode switched on with completion: a licence upgrade enables command execution for everyone without the controls tier 3 needs.
- Relying on version control ignore files to keep environment files and keys out of context.
- Auto-approve in untrusted repositories: developers disable approval prompts and then open a cloned project with hostile instructions; the agentjacking through a fake error report shows attacker content reaching an agent through a connected tool.
- Review by summary: reviewers read the agent's description, not the lockfile and workflow changes in the diff.
- Shared bot token for CI agents with write access to every repository.
- Unpinned extensions: the assistant auto-updates outside software distribution, so a compromised release reaches every workstation at once.
Practitioner checklist
- Agree data handling terms and enabled capability tiers before the pilot.
- Assign seats through the identity provider and block personal accounts.
- Configure the tool's own context exclusions and move secrets out of project trees.
- Publish a reviewed instructions baseline and protect rules and workflow files.
- Put branch protection, static analysis, secret scanning and dependency checks on every pull request.
- Run agent tiers in sandboxes with tool allowlists, egress limits and task-scoped credentials.
- Give CI agents dedicated least-privilege tokens and an approval gate.
- Test canary secrets and hostile instructions before each wave; practise rollback levers.
- Report managed adoption, change ownership and unreviewed rules changes monthly.
Standards and references
- OWASP: Secure Coding with AI Cheat Sheet
- OpenSSF: Security-Focused Guide for AI Code Assistant Instructions
- NIST: SP 800-218A Secure Software Development Practices for Generative AI and Dual-Use Foundation Models
- OWASP: Top 10 for LLM Applications 2025
- OWASP: LLM Prompt Injection Prevention Cheat Sheet
- NIST: SP 800-53 Rev. 5 Security and Privacy Controls
- NIST: Cybersecurity Framework 2.0
- NCSC: Guidelines for secure AI system development
Related NHI Mgmt Group resources: AI-Generated Code Review Guide · AI Coding Agent Incident Playbook · Developer Workstation and IDE Security Guide · LLM observability platform rollout playbook