Never treat AI-generated code as trusted just because it looks polished or includes comments. Read what it does, verify every dependency, and test it with non-sensitive sample data before it can reach your real files, credentials, website, or cloud account.
Start by defining what the code is allowed to change
Write down the expected inputs, outputs, files, network services, and accounts before running anything. A small script that renames photos should not need access to browser passwords, an entire home directory, a production database, or a cloud administrator account. If the requested permissions are wider than the task, stop and inspect why.
Ask for a plain-language explanation of each command, but do not let the same AI explanation replace your own review. If you are not comfortable identifying file deletion, credential access, downloads, and network calls, ask a knowledgeable person to review the code.
Look for destructive or secret-handling instructions
Search for commands that delete or overwrite files, recursively change permissions, format disks, reset repositories, modify startup settings, or send data over the network. Check whether database statements update or delete more rows than intended. A backup is useful only if it is separate from the files the script can overwrite.
Replace real passwords, API keys, personal records, and customer data with test values. Secrets should come from an approved secret store or environment setup, not be pasted directly into source code. If a generated example contains a credential placeholder, do not replace it inside a file that may be shared or committed.
Verify every package and external download
AI tools can suggest a package name that is misspelled, outdated, abandoned, or nonexistent. Visit the language’s official package registry or the software vendor’s official site, confirm the exact name and maintainer, and check the documentation before installing it. Do not follow a generated link to an unknown installer or copy a command that downloads and immediately executes a remote script.
Review version constraints and the lock file. A new dependency should solve a real need, have a compatible licence, and not duplicate something already in the project. GitHub’s official review guidance specifically warns about hallucinated or suspicious packages and recommends scrutinising dependencies.
Test in a limited and reversible environment
Use a disposable test project, a separate development account, or a non-production environment with fake data. Start without elevated privileges. Take a backup or snapshot, then run the smallest relevant unit or integration test before a full workflow. Compare the file and database state before and after.
A container or virtual machine can limit some damage, but it is not permission to run obviously unsafe code. Do not mount sensitive folders, forward production credentials, or expose unnecessary network access to the test environment.
Review behaviour, not only syntax
Code can compile and still solve the wrong problem. Test expected cases, empty input, invalid input, large input, interrupted operations, and failed network calls. Confirm that authentication and authorisation checks happen on the server side, user input is validated, logs do not reveal secrets, and error handling does not silently discard data.
Use your normal formatter, linter, static analysis, dependency scanner, and test suite. A second human reviewer is especially important for payments, account access, health information, security controls, and public-facing services. NIST’s Secure Software Development Framework treats code review and testing as continuing development practices, not optional finishing steps.
Check the final diff before accepting the result
Review every changed file and make sure generated tests were not weakened, skipped, or deleted to make a build pass. Check for unrelated formatting churn that can hide a risky line. Commit a small, understandable change only after the tests pass and you can explain what it does.
For non-code answers, the same habit applies: use the checks in how to tell whether an AI answer is reliable. If an AI tool invents references, follow the source-verification steps in this guide.
Checked against GitHub and NIST guidance on August 29, 2026. Your organisation’s review, security, privacy, and software-licensing policies take priority.



