04 Build Your AI Security Lab
AI Security becomes much easier to understand when you can build, test, observe and investigate systems yourself.
In this lesson, you will prepare a reusable AI Security Lab that will support the practical activities throughout the AI Security Engineer Learning Path.
Your lab does not need to be expensive or complicated.
The goal is to create a controlled environment where you can safely practice:
- AI application security
- LLM security testing
- API security
- RAG security
- AI agent security
- Cloud security
- Identity and access testing
- Container security
- Logging and investigation
- Threat modeling
- AI security automation
- Security documentation
By the end of this lesson, you should have a practical workstation structure ready for future labs.
Learning Objectives
Section titled βLearning ObjectivesβBy completing this lesson, you should be able to:
- Understand the purpose of an AI Security Lab.
- Prepare a secure workstation for AI security learning.
- Install the core tools required for future labs.
- Create a reusable project structure.
- Prepare Python and Git environments.
- Understand where Docker fits into AI security.
- Prepare tools for API testing.
- Understand options for running local AI models.
- Prepare for future cloud-based AI labs.
- Create a documentation and evidence structure.
- Follow safe and ethical testing boundaries.
- Validate that your lab environment is ready.
Why Build a Dedicated Lab?
Section titled βWhy Build a Dedicated Lab?βSecurity professionals should avoid experimenting directly in production environments.
A lab gives you a controlled environment where mistakes become learning opportunities rather than incidents.
You can:
Build βBreak βObserve βInvestigate βFix βRepeatThis cycle is extremely valuable.
For example, later you may intentionally create an insecure AI application to understand:
-
Why prompt injection works
-
How insecure API permissions create risk
-
How sensitive data can leak
-
How excessive AI agent permissions become dangerous
-
How logs can reveal suspicious behavior
You can then implement security controls and observe the difference.
Your AI Security Lab Architecture
Section titled βYour AI Security Lab ArchitectureβYour initial environment can be simple.
Your Workstation β βββ Visual Studio Code β βββ Git β βββ Python β βββ Docker β βββ API Testing Tools β βββ Browser β βββ Local AI Tools β βββ Security Utilities β βΌ AI Security Labs β βββ LLM Applications βββ APIs βββ RAG βββ AI Agents βββ Containers βββ Cloud Services βββ Security LogsYou will expand this environment gradually.
Do not install every security tool you have heard about.
Start with the tools required for learning.
Mission Information
Section titled βMission InformationβMission: Build Your AI Security Lab
Difficulty: Beginner
Estimated Time: 45β90 minutes
Primary Goal: Prepare a safe and reusable environment for AI Security Engineer labs.
Environment: Windows, macOS or Linux
Cost: Most components can be built using free tools.
Recommended Workstation
Section titled βRecommended WorkstationβYou can complete many labs using a normal modern computer.
A practical starting point is:
| Component | Recommended |
|---|---|
| CPU | Modern multi-core processor |
| RAM | 8 GB minimum, 16 GB recommended |
| Storage | At least 20β40 GB free |
| Operating System | Windows, Linux or macOS |
| Internet | Required for cloud/API labs |
| Browser | Modern browser |
| Virtualization | Recommended |
For running larger AI models locally, additional RAM or GPU resources may help.
However:
You do not need an expensive GPU to begin learning AI Security.
Many security concepts can be practiced with lightweight local models, APIs, containers and intentionally vulnerable applications.
Step 1 β Create Your Lab Directory
Section titled βStep 1 β Create Your Lab DirectoryβCreate one central directory for your AI Security work.
Windows
Section titled βWindowsβOpen PowerShell:
mkdir C:\AI-Security-Labcd C:\AI-Security-LabLinux or macOS
Section titled βLinux or macOSβmkdir -p ~/AI-Security-Labcd ~/AI-Security-LabCreate the initial structure:
AI-Security-Lab/ββββ 01-Projects/βββ 02-Labs/βββ 03-Tools/βββ 04-Scripts/βββ 05-Logs/βββ 06-Evidence/βββ 07-Threat-Models/βββ 08-Runbooks/βββ 09-Notes/This structure can evolve as your learning progresses.
Why This Structure Matters
Section titled βWhy This Structure MattersβProfessional security work generates more than commands.
You may eventually create:
-
Screenshots
-
Security findings
-
API responses
-
Architecture diagrams
-
Logs
-
Threat models
-
Python scripts
-
Investigation notes
-
Runbook outputs
-
Remediation reports
Organizing evidence from the beginning develops good professional habits.
Step 2 β Install Visual Studio Code
Section titled βStep 2 β Install Visual Studio CodeβVisual Studio Code can serve as your primary workspace for:
-
Python
-
JSON
-
YAML
-
Markdown
-
Docker files
-
API payloads
-
Configuration files
-
Git repositories
-
Security notes
After installation, consider extensions for:
-
Python
-
Docker
-
YAML
-
Markdown
-
Git
Avoid installing unnecessary extensions.
Each extension increases complexity and potentially expands your local software attack surface.
Step 3 β Install Git
Section titled βStep 3 β Install GitβGit will be useful throughout the learning path.
You can use it to:
-
Download lab repositories
-
Track configuration changes
-
Maintain scripts
-
Build your portfolio
-
Document projects
-
Compare versions
Validate installation:
git --versionYou should see a version number.
Configure Git Identity
Section titled βConfigure Git IdentityβIf this is your personal learning environment:
git config --global user.name "Your Name"git config --global user.email "your-email@example.com"Check the configuration:
git config --global --listNever store passwords, API keys or access tokens directly inside Git repositories.
Step 4 β Install Python
Section titled βStep 4 β Install PythonβPython is one of the most useful languages across both AI and cybersecurity.
You will use Python for activities such as:
-
Calling AI APIs
-
Working with JSON
-
Automating security tasks
-
Parsing logs
-
Building small AI applications
-
Testing security scenarios
-
Processing data
Validate Python:
python --versionor:
python3 --versionYou should see a supported Python version.
Step 5 β Understand Python Virtual Environments
Section titled βStep 5 β Understand Python Virtual EnvironmentsβAvoid installing every Python package globally.
Use virtual environments for individual projects.
Create one:
python -m venv .venvWindows PowerShell
Section titled βWindows PowerShellβ.\.venv\Scripts\Activate.ps1Linux or macOS
Section titled βLinux or macOSβsource .venv/bin/activateWhen activated, your terminal should indicate that .venv is being used.
Upgrade pip:
python -m pip install --upgrade pipWhy Virtual Environments Matter
Section titled βWhy Virtual Environments MatterβDifferent AI projects may require different package versions.
Without isolation:
Project A β βββ Package Version 1
Project B β βββ Package Version 2may conflict.
Virtual environments isolate dependencies.
This is not only a development practice.
It is also useful for reproducibility and security.
Step 6 β Create a Simple Python Validation Script
Section titled βStep 6 β Create a Simple Python Validation ScriptβInside:
04-Scripts/create:
environment_check.pyAdd:
import platformimport sys
print("AI Security Lab Environment")print("---------------------------")print(f"Operating System: {platform.system()}")print(f"Python Version: {sys.version}")print("Environment validation completed.")Run:
python environment_check.pyExpected result:
AI Security Lab Environment---------------------------Operating System: ...Python Version: ...Environment validation completed.Your Python environment is working.
Step 7 β Install Docker
Section titled βStep 7 β Install DockerβDocker will become useful for running isolated lab applications.
You may later use containers for:
-
Vulnerable AI applications
-
LLM security labs
-
APIs
-
Databases
-
Vector databases
-
Logging platforms
-
Supporting services
Validate installation:
docker --versionThen:
docker run hello-worldIf the test completes successfully, Docker is ready.
Why Docker Matters for AI Security
Section titled βWhy Docker Matters for AI SecurityβImagine a lab needs:
AI Application +API +Vector Database +Supporting ServiceInstalling each manually can become difficult.
Docker allows the environment to be defined as containers.
For example:
Docker Host β βββ AI Application Container βββ API Container βββ Database Container βββ Logging ContainerAfter completing a lab, you can remove the environment and rebuild it later.
This improves:
-
Repeatability
-
Isolation
-
Cleanup
-
Troubleshooting
Step 8 β Install an API Testing Tool
Section titled βStep 8 β Install an API Testing ToolβModern AI systems depend heavily on APIs.
You should become comfortable inspecting requests and responses.
Common options include:
-
Postman
-
Bruno
-
Insomnia
-
curl
You do not need all of them.
Choose one graphical client and learn curl as well.
Validate curl
Section titled βValidate curlβRun:
curl --versionYou should see version information.
Why API Skills Matter
Section titled βWhy API Skills MatterβA typical AI application may communicate like:
Application β β HTTPS βΌAI API β βΌModelSecurity issues may exist in:
-
Authentication
-
Authorization
-
Headers
-
Tokens
-
Input validation
-
Output handling
-
Rate limits
-
API permissions
-
Error handling
Understanding API traffic is therefore an essential AI Security Engineer skill.
Step 9 β Understand JSON
Section titled βStep 9 β Understand JSONβMost AI APIs exchange data using JSON.
A request may resemble:
{ "model": "example-model", "messages": [ { "role": "user", "content": "Explain least privilege." } ]}A response might resemble:
{ "result": "Least privilege means..."}You should become comfortable:
-
Reading JSON
-
Editing JSON
-
Identifying nested objects
-
Understanding arrays
-
Recognizing input and output fields
This will make later API security labs much easier.
Step 10 β Prepare a Browser for Security Testing
Section titled βStep 10 β Prepare a Browser for Security TestingβYour browser is also an important testing tool.
Become familiar with browser developer tools.
Typically open them using:
F12or:
Ctrl + Shift + IImportant areas include:
Network
Section titled βNetworkβObserve:
-
API requests
-
HTTP methods
-
Response codes
-
Headers
-
Request bodies
-
Responses
Application / Storage
Section titled βApplication / StorageβObserve:
-
Cookies
-
Local storage
-
Session storage
Console
Section titled βConsoleβObserve:
-
Client-side errors
-
JavaScript output
-
Debug information
Do not modify or test systems without authorization.
Step 11 β Prepare an API Request Workspace
Section titled βStep 11 β Prepare an API Request WorkspaceβCreate:
01-Projects/API-Testing/Inside it, you can later store:
requests/responses/notes/examples/Never save live credentials or API keys inside files intended for source control.
Step 12 β Learn Environment Variables
Section titled βStep 12 β Learn Environment VariablesβAI applications frequently require API credentials.
Instead of hardcoding:
api_key = "my-secret-key"applications should use safer mechanisms such as environment variables or managed secret stores.
Example concept:
Application β βΌEnvironment Variable β βΌAPI CredentialIn future labs, you will learn how credentials are securely handled.
Step 13 β Create a .gitignore
Section titled βStep 13 β Create a .gitignoreβIn the root of your lab repository, create:
.gitignoreExample:
.venv/.env.env.*__pycache__/*.logsecrets/credentials/*.pem*.keyThis helps reduce the risk of accidentally committing sensitive files.
However:
.gitignoreis not a security control by itself.
Always review your files before committing.
Step 14 β Understand .env Files
Section titled βStep 14 β Understand .env FilesβMany applications use .env files.
Example:
AI_API_KEY=exampleDATABASE_PASSWORD=exampleTreat these files as sensitive.
They should generally not be committed to a public repository.
Your repository can instead contain:
.env.exampleExample:
AI_API_KEY=DATABASE_PASSWORD=This documents required configuration without exposing credentials.
Step 15 β Prepare for Local AI Models
Section titled βStep 15 β Prepare for Local AI ModelsβYou may later want to run models locally.
Local models can be useful for:
-
Learning
-
Testing prompts
-
Building experimental applications
-
Security research
-
Offline testing
-
Understanding model interactions
Possible local AI environments may include tools that allow you to download and run compatible models on your workstation.
The specific platform is less important than understanding the architecture.
User β βΌLocal Application β βΌLocal Model Runtime β βΌLLMRunning locally can reduce dependency on external APIs for some labs.
However, local models still require security considerations such as:
-
Model provenance
-
Dependency security
-
Resource usage
-
Data handling
-
Model files
-
Application security
Step 16 β Understand Cloud AI Labs
Section titled βStep 16 β Understand Cloud AI LabsβSome later AI security exercises may require cloud platforms.
An enterprise architecture may use:
Cloud Account β βββ Identity βββ Storage βββ Networking βββ AI Service βββ Database βββ Logging βββ Security MonitoringYou do not need to configure all cloud platforms now.
When required, individual labs will explain the necessary setup.
Cloud Cost Warning
Section titled βCloud Cost WarningβCloud environments may generate charges.
Before creating resources:
-
Read the entire lab.
-
Understand which services are required.
-
Check current pricing.
-
Use free or low-cost options where possible.
-
Delete resources after completing the exercise.
Never leave lab infrastructure running unnecessarily.
Step 17 β Prepare a Cloud Lab Folder
Section titled βStep 17 β Prepare a Cloud Lab FolderβCreate:
02-Labs/Cloud/Later you can organize cloud exercises such as:
Cloud/βββ IAM/βββ AI-Services/βββ Logging/βββ Containers/βββ Incident-Response/Step 18 β Prepare Security Testing Utilities
Section titled βStep 18 β Prepare Security Testing UtilitiesβAs you progress, you may encounter tools for:
-
HTTP inspection
-
API testing
-
Code analysis
-
Dependency analysis
-
Container analysis
-
LLM testing
-
Logging
-
Cloud assessment
Do not install everything immediately.
A good engineering rule is:
Install a tool when you understand why you need it.
For every tool, ask:
What problem does it solve?
What permissions does it require?
Where did it come from?
Is the source trusted?
What data can it access?
How do I remove it?This is especially important for security tools downloaded from public repositories.
Step 19 β Create Your Evidence Structure
Section titled βStep 19 β Create Your Evidence StructureβInside:
06-Evidence/create folders such as:
06-Evidence/βββ Screenshots/βββ Logs/βββ Findings/βββ Reports/βββ Validation/For every lab, try to capture enough evidence to demonstrate what occurred.
Evidence Example
Section titled βEvidence ExampleβSuppose you identify an overly permissive AI service account.
Your evidence might include:
Finding:AI service account has excessive permissions.
Evidence:Screenshot of assigned role.
Validation:Demonstration that the account can access an unrelated resource.
Risk:Compromise of the application could expose additional resources.
Recommendation:Apply least privilege.This transforms a technical observation into a professional security finding.
Step 20 β Create Your Threat Modeling Folder
Section titled βStep 20 β Create Your Threat Modeling FolderβCreate:
07-Threat-Models/You may later store:
-
Architecture diagrams
-
Data flow diagrams
-
Asset inventories
-
Trust boundaries
-
Threat lists
-
Attack paths
-
Security controls
A threat model might eventually include:
User β β Untrusted Input βΌAI Application β β API Call βΌLLM β βββ Vector Database βββ Enterprise Data βββ Agent ToolsThen you begin asking:
Where are the trust boundaries?
Where can input be manipulated?
Where can sensitive data leak?
What permissions exist?
Step 21 β Prepare Your Runbook Folder
Section titled βStep 21 β Prepare Your Runbook FolderβCreate:
08-Runbooks/Later, this may contain runbooks such as:
LLM-Security-Investigation.md
AI-Incident-Response.md
RAG-Security-Assessment.md
AI-Agent-Security-Review.mdThese help develop operational thinking.
Step 22 β Build Your Lab Notes Template
Section titled βStep 22 β Build Your Lab Notes TemplateβInside:
09-Notes/create:
Lab-Template.mdUse:
# Lab Name
## Mission
## Objective
## Environment
## Architecture
## Tools Used
## Steps Performed
## Observations
## Security Findings
## Evidence
## Remediation
## Validation
## What I Learned
## Questions for Further InvestigationCopy this template for future labs.
Step 23 β Prepare a Findings Template
Section titled βStep 23 β Prepare a Findings TemplateβCreate:
Finding-Template.mdUse:
# Security Finding
## Finding Title
## Severity
## Affected Asset
## Description
## Evidence
## Security Impact
## Attack Scenario
## Recommendation
## Validation
## ReferencesThis introduces professional reporting habits early.
Step 24 β Create a README
Section titled βStep 24 β Create a READMEβInside your main lab folder, create:
README.mdExample:
# AI Security Lab
Personal learning environment for AI Security Engineering.
## Areas
- AI Security- LLM Security- RAG Security- AI Agent Security- Cloud Security- Threat Modeling- AI Red Teaming- Security Operations
## Purpose
This repository contains hands-on learning exercises,security notes, threat models and projects created whiledeveloping AI Security Engineering skills.Do not add personal credentials or sensitive data.
Step 25 β Understand the Safe Testing Boundary
Section titled βStep 25 β Understand the Safe Testing BoundaryβThis is one of the most important parts of the lab.
Security testing should be performed only against:
-
Systems you own
-
Your own lab applications
-
Intentionally vulnerable training environments
-
Systems where you have explicit authorization
-
Approved security testing environments
Do not assume that a publicly accessible system is authorized for security testing.
Public access does not equal permission.
Your Testing Boundary
Section titled βYour Testing BoundaryβThink of your environment as:
AUTHORIZEDββββββββββββββββββββββββββββYour LabYour ContainersYour Test APIsYour Cloud SandboxApproved Training TargetsSystems With Written Permissionββββββββββββββββββββββββββββ
NOT AUTHORIZEDββββββββββββββββββββββββββββRandom WebsitesPublic AI ServicesOther People's APIsCompany Systems Without ApprovalExternal Cloud AccountsUnknown Internet TargetsββββββββββββββββββββββββββββAlways stay inside the authorized boundary.
Step 26 β Protect Your Credentials
Section titled βStep 26 β Protect Your CredentialsβAI labs may eventually use:
-
API keys
-
Cloud credentials
-
Tokens
-
SSH keys
-
Service accounts
Treat all of them as secrets.
Never:
Paste credentials into screenshotsCommit them to GitShare them in public repositoriesStore them in documentationPost them in forumsReuse production credentialsPrefer dedicated lab credentials with minimal permissions.
Step 27 β Separate Lab and Production Accounts
Section titled βStep 27 β Separate Lab and Production AccountsβWhere possible:
Production Account β Learning Lab AccountA separate sandbox reduces the impact of mistakes.
For example:
Personal Learning Cloud Account β βββ Lab IAM Users βββ Lab Resources βββ Lab Logs βββ Temporary ExperimentsDo not use an employerβs production environment for personal training.
Step 28 β Apply Least Privilege to Your Lab
Section titled βStep 28 β Apply Least Privilege to Your LabβEven a lab should reinforce good security practices.
Instead of granting:
Administrator Accesseverywhere, try to understand what permissions are actually required.
This helps you learn IAM while improving your lab security.
Step 29 β Keep Your Environment Updated
Section titled βStep 29 β Keep Your Environment UpdatedβSecurity tools and AI frameworks change rapidly.
Periodically review:
-
Operating system updates
-
Python packages
-
Docker
-
Browser
-
IDE
-
Security tools
-
AI libraries
But do not blindly update the night before an important lab.
Updates can introduce compatibility changes.
Understand what changed.
Step 30 β Create a Lab Snapshot Strategy
Section titled βStep 30 β Create a Lab Snapshot StrategyβBefore major experiments, preserve important files.
You may use:
-
Git commits
-
Virtual machine snapshots
-
Container images
-
Configuration backups
-
Cloud Infrastructure as Code
A useful pattern is:
Known Good Environment βSave State βPerform Experiment βBreak Something βInvestigate βRestore If RequiredThis makes experimentation safer.
Step 31 β Validate Your Lab
Section titled βStep 31 β Validate Your LabβUse this checklist.
Workstation
Section titled βWorkstationβ-
Operating system ready
-
Sufficient storage available
-
Browser installed
Development Environment
Section titled βDevelopment Environmentβ-
Visual Studio Code installed
-
Git installed
-
Python installed
-
Python virtual environment tested
Container Environment
Section titled βContainer Environmentβ-
Docker installed
-
Docker test container runs successfully
API Environment
Section titled βAPI Environmentβ-
curl available
-
API testing client available
-
Basic JSON understood
Security Environment
Section titled βSecurity Environmentβ-
Lab directories created
-
Evidence folders created
-
Threat modeling folder created
-
Runbook folder created
-
Notes template created
-
Findings template created
Security Hygiene
Section titled βSecurity Hygieneβ-
.gitignorecreated -
Secrets excluded from Git
-
Lab credentials separated where possible
-
Testing boundaries understood
If these are complete, your core environment is ready.
Recommended Lab Structure
Section titled βRecommended Lab StructureβYour final structure may resemble:
AI-Security-Lab/ββββ README.mdβββ .gitignoreββββ 01-Projects/ββ βββ API-Testing/ββββ 02-Labs/β βββ Cloud/ββββ 03-Tools/ββββ 04-Scripts/β βββ environment_check.pyββββ 05-Logs/ββββ 06-Evidence/β βββ Screenshots/β βββ Logs/β βββ Findings/β βββ Reports/β βββ Validation/ββββ 07-Threat-Models/ββββ 08-Runbooks/ββββ 09-Notes/ βββ Lab-Template.md βββ Finding-Template.mdYou do not need to fill every directory immediately.
The structure is there so the lab can grow with you.
How This Lab Will Evolve
Section titled βHow This Lab Will EvolveβAt the beginning:
Workstation+Python+Git+DockerLater:
AI Applications+LLM APIs+RAG+Vector DatabasesThen:
AI Agents+Cloud Infrastructure+Security Monitoring+Threat ModelingEventually:
Enterprise AI Security EnvironmentThe lab grows as your skills grow.
Security Engineer Habit
Section titled βSecurity Engineer HabitβEvery time you add a new component to your environment, ask:
What is this?
Why do I need it?
What data does it access?
What privileges does it require?
What attack surface does it create?
How is it updated?
How would I detect misuse?
How would I remove it?That simple habit is already AI Security Engineering thinking.
What You Should Have Learned
Section titled βWhat You Should Have LearnedβYou should now understand that your AI Security Lab is more than a collection of tools.
It is an environment for practicing the complete security lifecycle:
Build βUnderstand βThreat Model βSecure βTest βObserve βInvestigate βRemediate βDocumentThis environment will become the foundation for your labs and enterprise projects throughout the learning path.
Lab Readiness Check
Section titled βLab Readiness CheckβBefore moving forward, make sure you can answer:
Where will I store my labs?
Where will I store evidence?
How will I isolate Python dependencies?
How will I run containerized applications?
How will I test APIs?
How will I protect API keys?
How will I document findings?
What systems am I authorized to test?
If you can answer these questions, your lab has a solid foundation.
Whatβs Next?
Section titled βWhatβs Next?ββ‘οΈ 05 β Responsible and Ethical AI Security Testing
Before beginning technical AI security modules, one final foundation is required:
authorization and responsible security testing.
In the next lesson, you will learn:
-
Why authorization matters
-
How security testing scope works
-
Rules of engagement
-
Responsible AI red teaming
-
Safe testing boundaries
-
Data handling requirements
-
Testing third-party AI systems
-
Vulnerability disclosure
-
Evidence handling
-
Professional security ethics
This will establish the boundaries within which all future AI security labs and assessments should operate.
β‘οΈ Next: 05 β Responsible and Ethical AI Security Testing