AI in Cybersecurity and Ethical Hacking: Best Practices
Explore AI in cybersecurity and ethical hacking with best practices for AI-assisted testing, supply chain security, and prompt injection defense.

Map the application before you scan it
A RAG application’s config.yaml, container image, package lockfile, CI workflow, vector database, and API keys are all part of the target. If you only test the chat interface, you will miss much of the system that can fail.
IBM Technology describes this larger picture as the software supply chain: application code plus open-source packages, transitive dependencies, base images, build pipelines, secrets, and AI-generated code. An attacker needs one weak entry point, not a flaw in every layer.
Create a one-page system map before running automated scanners or asking an AI assistant for attack ideas. List repositories, registries, cloud accounts, models, data stores, build runners, agent tools, service accounts, and external APIs.
Mark what can read data, write data, execute code, deploy artifacts, or access credentials. Those capabilities define your highest-risk paths. A chatbot that can only answer from public documentation presents a different test surface from one that can open tickets or trigger deployments.
We would start with the CI/CD runner and the service identities available to it. A compromised build can distribute a trusted-looking artifact across many environments, which is why software supply-chain attacks often have a much larger blast radius than a single application bug.
Get permission and build an ethical test boundary
Put the scope in writing before testing anything. Identify the systems, domains, repositories, cloud tenants, accounts, testing windows, rate limits, escalation contacts, and prohibited actions, including whether production data may be accessed or copied.
Your authorization should state whether social engineering, credential testing, phishing simulations, destructive actions, persistence testing, and third-party services are permitted. AI can rapidly produce test cases and scan candidates, which makes clear constraints even more important.
Use a staging environment for tests that could create records, invoke tools, consume paid APIs, modify vector-store content, or trigger workflows. Seed it with non-sensitive documents that resemble the formats your production system processes.
Keep an evidence log from the start. Record the test prompt or request, timestamp, target, account used, raw response, observed impact, and remediation recommendation. That turns an AI-generated lead into a finding an engineering team can reproduce.
NIST’s software supply-chain guidance, developed under the 2021 Executive Order on Improving the Nation’s Cybersecurity, centers risk management around knowing what software you use and securing how it is built and delivered. [1]
Inventory every supplier, including the AI system
Generate a software bill of materials, or SBOM, for each build. It should identify direct and transitive packages, versions, licenses, container layers, operating-system packages, build tools, and the artifact produced by the pipeline.
Then create an AI bill of materials alongside it. Record the foundation model and version, embedding model, system prompt, guardrail configuration, retrieved knowledge sources, vector database, tool definitions, agent permissions, evaluation data, and model-provider endpoints.
This inventory is what you consult when a vulnerable dependency, poisoned package, exposed key, or model-integrity concern emerges. Without it, teams often search repositories and deployed systems manually while a vulnerability is already being exploited.
IBM Technology uses Log4j to illustrate the issue. The logging library appeared as a dependency across many applications, and its remote-code-execution flaw was difficult to remediate because teams had to locate affected versions across varied environments.
Include generated code in code ownership and review records. A comment saying that an assistant produced a function is less important than recording the prompt context, developer review, tests run, dependencies added, and artifact that ultimately reached production.
Supply-chain security guidance from Chainguard recommends component traceability, strict access control, secrets management, signed artifacts, and continuous monitoring for AI systems as well as conventional software. [2]
Keep AI-generated changes narrow and reviewable
Ask coding assistants for one function, one dependency upgrade, or one test case at a time. Do not accept a broad pull request that mixes an authentication change, a framework migration, a package update, and generated documentation.
Small changes help reviewers isolate cause and effect. They also make it easier to revert an unsafe suggestion, identify which dependency introduced it, and compare the diff against the ticket or threat model that justified the change.
Run secret detection on every commit and pull request. Generated code can reproduce credentials from a developer’s context, hardcode tokens into examples, or introduce connection strings that work in a test environment but later reach a public repository.
Scan dependencies before merge, then repeat the scan during the build. Check known vulnerabilities, package integrity, typosquatting risk, unexpected maintainers, and whether a package name resolves from the registry you intended to use.
Package-registry attacks often rely on names that resemble popular dependencies. IBM Technology highlights typosquatting and compromised maintainer accounts as two routes by which malicious code can enter a project through a normal-looking update.
We would block dependency additions that lack a clear owner, version pin, license review, and integrity check. Speed gained by accepting an assistant’s suggested package disappears when the team later has to unwind an untracked dependency across services.
Put security gates in the build pipeline
Move checks close to the code change. Scan commits for exposed secrets, validate dependencies before installation, run static analysis, execute unit and integration tests, and evaluate generated infrastructure code before it receives cloud credentials.
Do not let an AI agent both author a change and be the sole reviewer of it. IBM Technology recommends independent verification, using a separate model or separate review session, because the same system may repeat the same mistaken assumption.
Use deterministic controls for high-impact actions. An agent should not deploy code, rotate credentials, change access policies, or publish packages solely because a model classified a request as safe. Require policy checks and named human approval.
Sign source and build artifacts, then verify signatures before deployment. The SLSA framework gives teams a structured way to document provenance, including where artifacts came from, what process built them, and what checks occurred before release.
Sysdig’s 2026 supply-chain recommendations similarly emphasize controlling the build environment, scanning artifacts, limiting permissions, and continuously monitoring runtime behavior. [3] A clean build does not guarantee a safe deployment if credentials or runtime controls are weak.
Test prompt injection at every boundary
Start with the user-input boundary. Test whether a prompt can override the system’s purpose, request hidden instructions, alter its role, or persuade the application to invoke a tool outside the user’s authority.
Then test retrieved content. Place authorized test documents in the knowledge base containing misleading instructions, requests to reveal private data, or text that tries to redirect the model’s behavior. Verify that retrieved text is treated as untrusted data.
Krish Naik’s NeMo Guardrails tutorial separates these concerns into input, retrieval, dialogue, execution, and output rails. This is a useful design model because a clean user prompt can still retrieve a hostile document.
Test tool calls separately from text generation. Confirm that the model cannot use a retrieved instruction or a user message to access files, call administrative APIs, change deployment settings, or send data to an unapproved destination.
Prompt injection is difficult because language models process instructions and data in the same context window. A filter can catch familiar patterns, but application architecture must still limit what the model can read, call, and disclose.
Configure guardrails as policy checks, not magic armor
NVIDIA NeMo Guardrails is an open-source Python toolkit that adds programmable checks around an LLM application. In Krish Naik’s example, configuration defines whether input, retrieved material, or output should be allowed, modified, or blocked.
Write narrow policies for each stage. An input rail can reject requests outside an assistant’s domain, while a retrieval rail can block documents containing sensitive information or instruction-like content that should not reach the model context.
An output rail can prevent the assistant from returning secrets, internal system details, or off-topic content. Dialogue rails constrain conversational paths, and execution rails can limit which tools an agent may invoke under which conditions.
Do not rely on a rail’s yes-or-no model judgment as your authorization system. Enforce user identity, role, tenant boundary, data classification, and tool permissions in conventional application code before any action runs.
Test bypass attempts using paraphrases, multilingual inputs, encoded text, conflicting instructions, and benign-looking documents with malicious instructions embedded in long passages. Record false blocks too, because guardrails that disrupt legitimate work will be bypassed by users.
Use AI to widen testing coverage, then validate manually
Let AI help create test cases from API specifications, authentication flows, architecture diagrams, error messages, and code diffs. It can cluster repeated scanner results, summarize logs, and suggest where an exposed service connects to sensitive data.
TechRadar reported that an AI-assisted cybersecurity team found a large set of OpenSSL vulnerabilities, with the work praised for report quality and constructive collaboration. [5] This points to a productive role for automation in finding and organizing leads.
Do not report every AI-generated finding as a vulnerability. Reproduce it with the minimum authorized request, verify the affected version and configuration, establish preconditions, and show the real impact without exceeding agreed test boundaries.
Experienced testers remain necessary for multi-step attacks and business-logic flaws. An AI tool can notice that an endpoint accepts an identifier, but a human has to determine whether changing that identifier bypasses a tenant boundary or violates a business rule.
Prioritize confirmed findings by exploitability and impact. A public, unauthenticated path to sensitive data outranks a theoretical issue in an isolated service with strict controls, even if an automated tool assigns both a dramatic severity label.
Prepare the response path before a finding arrives
Create an owner for each component in your SBOM and AI inventory. When a dependency advisory, compromised package, prompt-injection report, or secret leak appears, the owner should know what service uses it and how to reach the deployment team.
Practice a rollback of an AI-generated change. Confirm that you can restore the previous image, revoke an exposed token, disable a risky agent tool, remove a poisoned document, and invalidate cached responses without improvising under pressure.
IBM Technology points to Project Akrites from the Linux Foundation and Red Hat and IBM’s Lightwell as initiatives intended to provide remediated packages when a straight upgrade could break an application. Use patched components only after validating compatibility in your environment.
Finish every engagement with a retest. Verify the fix in the same path used to demonstrate the original issue, check that the mitigation did not create a new access route, and update the relevant policy, test suite, inventory, and incident playbook.
Frequently Asked Questions
How can AI improve penetration testing in cybersecurity?
AI can expand test coverage and speed up triage by rapidly producing test cases and scanning candidates. However, experienced testers must validate AI findings, test business logic, and determine exploitability to ensure accuracy and relevance.
What are best practices for securing AI-generated code?
Keep AI-generated changes narrow and reviewable by requesting one function or dependency update at a time. Conduct thorough code reviews, run secret detection on every commit, scan dependencies for vulnerabilities and integrity, and maintain clear ownership and version control for all additions.
How do you manage software supply chain risks with AI components?
Treat AI models, prompts, plugins, and generated code as suppliers in the software supply chain. Generate a software bill of materials (SBOM) and an AI component inventory before production, sign builds, verify provenance in CI/CD pipelines, and continuously monitor for vulnerabilities or compromised components.
How can prompt injection attacks be tested and mitigated?
Use guardrails to filter prompt injection and unsafe outputs, but maintain sensitive actions behind deterministic authorization checks and human approval. Because prompt injection may never be fully preventable, rely on layered defenses including monitoring, human oversight, and strict access controls rather than solely on model-provider guardrails.
How we researched this
This article was assembled from 2 video sources across 2 channels, 5 cited references.
Nothing here is based on hands-on testing. Where a figure or finding appears, it belongs to the source cited beside it, and the writing says so rather than implying otherwise. Every source is listed below so you can check it.
Sources
Software Supply Chain Security: What AI Coding Changes, IBM Technology
2-NVIDIA NeMo Guardrails Tutorial: Defend RAG Apps Against Prompt Injection | Part 1, Krish Naik
7 software supply chain security best practices in 2026 | Sysdig
Watch AI in Cybersecurity and Ethical Hacking on Youtube
Also from the sources
Related Articles

AI-Powered Coding Agents: Best Practices and Risks
Learn best practices, risks, and workflows for AI-powered coding agents to improve software development safely and effectively.

AI Code Review Best Practices for Software Development
Learn AI code review best practices, including evidence-based gates and modular skills, to improve software development and review workflows.

Spec-Driven Development with AI for Collaborative Software
Explore spec-driven development with AI collaboration tools to improve software quality through iterative specs and AI-assisted coding.

AI Security Vulnerabilities and Monitoring Challenges
Explore AI security vulnerabilities and monitoring challenges, with insights on detection, remediation, and best practices for AI systems.