Skip to content

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.

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.

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
↓
Repeat

This 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 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 Logs

You will expand this environment gradually.

Do not install every security tool you have heard about.

Start with the tools required for learning.

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.

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.

Create one central directory for your AI Security work.

Open PowerShell:

Terminal window
mkdir C:\AI-Security-Lab
cd C:\AI-Security-Lab
Terminal window
mkdir -p ~/AI-Security-Lab
cd ~/AI-Security-Lab

Create 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.

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.

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.

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:

Terminal window
git --version

You should see a version number.

If this is your personal learning environment:

Terminal window
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"

Check the configuration:

Terminal window
git config --global --list

Never store passwords, API keys or access tokens directly inside Git repositories.

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:

Terminal window
python --version

or:

Terminal window
python3 --version

You should see a supported Python version.

Avoid installing every Python package globally.

Use virtual environments for individual projects.

Create one:

Terminal window
python -m venv .venv
Terminal window
.\.venv\Scripts\Activate.ps1
Terminal window
source .venv/bin/activate

When activated, your terminal should indicate that .venv is being used.

Upgrade pip:

Terminal window
python -m pip install --upgrade pip

Different AI projects may require different package versions.

Without isolation:

Project A
β”‚
└── Package Version 1
Project B
β”‚
└── Package Version 2

may 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.py

Add:

import platform
import sys
print("AI Security Lab Environment")
print("---------------------------")
print(f"Operating System: {platform.system()}")
print(f"Python Version: {sys.version}")
print("Environment validation completed.")

Run:

Terminal window
python environment_check.py

Expected result:

AI Security Lab Environment
---------------------------
Operating System: ...
Python Version: ...
Environment validation completed.

Your Python environment is working.

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:

Terminal window
docker --version

Then:

Terminal window
docker run hello-world

If the test completes successfully, Docker is ready.

Imagine a lab needs:

AI Application
+
API
+
Vector Database
+
Supporting Service

Installing 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 Container

After completing a lab, you can remove the environment and rebuild it later.

This improves:

  • Repeatability

  • Isolation

  • Cleanup

  • Troubleshooting

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.

Run:

Terminal window
curl --version

You should see version information.

A typical AI application may communicate like:

Application
β”‚
β”‚ HTTPS
β–Ό
AI API
β”‚
β–Ό
Model

Security 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.

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.

Your browser is also an important testing tool.

Become familiar with browser developer tools.

Typically open them using:

F12

or:

Ctrl + Shift + I

Important areas include:

Observe:

  • API requests

  • HTTP methods

  • Response codes

  • Headers

  • Request bodies

  • Responses

Observe:

  • Cookies

  • Local storage

  • Session storage

Observe:

  • Client-side errors

  • JavaScript output

  • Debug information

Do not modify or test systems without authorization.

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.

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 Credential

In future labs, you will learn how credentials are securely handled.

In the root of your lab repository, create:

.gitignore

Example:

.venv/
.env
.env.*
__pycache__/
*.log
secrets/
credentials/
*.pem
*.key

This helps reduce the risk of accidentally committing sensitive files.

However:

.gitignore is not a security control by itself.

Always review your files before committing.

Many applications use .env files.

Example:

AI_API_KEY=example
DATABASE_PASSWORD=example

Treat these files as sensitive.

They should generally not be committed to a public repository.

Your repository can instead contain:

.env.example

Example:

AI_API_KEY=
DATABASE_PASSWORD=

This documents required configuration without exposing credentials.

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
β”‚
β–Ό
LLM

Running 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

Some later AI security exercises may require cloud platforms.

An enterprise architecture may use:

Cloud Account
β”‚
β”œβ”€β”€ Identity
β”œβ”€β”€ Storage
β”œβ”€β”€ Networking
β”œβ”€β”€ AI Service
β”œβ”€β”€ Database
β”œβ”€β”€ Logging
└── Security Monitoring

You do not need to configure all cloud platforms now.

When required, individual labs will explain the necessary setup.

Cloud environments may generate charges.

Before creating resources:

  1. Read the entire lab.

  2. Understand which services are required.

  3. Check current pricing.

  4. Use free or low-cost options where possible.

  5. Delete resources after completing the exercise.

Never leave lab infrastructure running unnecessarily.

Create:

02-Labs/Cloud/

Later you can organize cloud exercises such as:

Cloud/
β”œβ”€β”€ IAM/
β”œβ”€β”€ AI-Services/
β”œβ”€β”€ Logging/
β”œβ”€β”€ Containers/
└── Incident-Response/

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.

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.

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.

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 Tools

Then you begin asking:

Where are the trust boundaries?

Where can input be manipulated?

Where can sensitive data leak?

What permissions exist?

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.md

These help develop operational thinking.

Inside:

09-Notes/

create:

Lab-Template.md

Use:

# Lab Name
## Mission
## Objective
## Environment
## Architecture
## Tools Used
## Steps Performed
## Observations
## Security Findings
## Evidence
## Remediation
## Validation
## What I Learned
## Questions for Further Investigation

Copy this template for future labs.

Create:

Finding-Template.md

Use:

# Security Finding
## Finding Title
## Severity
## Affected Asset
## Description
## Evidence
## Security Impact
## Attack Scenario
## Recommendation
## Validation
## References

This introduces professional reporting habits early.

Inside your main lab folder, create:

README.md

Example:

# 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 while
developing AI Security Engineering skills.

Do not add personal credentials or sensitive data.

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.

Think of your environment as:

AUTHORIZED
────────────────────────────
Your Lab
Your Containers
Your Test APIs
Your Cloud Sandbox
Approved Training Targets
Systems With Written Permission
────────────────────────────
NOT AUTHORIZED
────────────────────────────
Random Websites
Public AI Services
Other People's APIs
Company Systems Without Approval
External Cloud Accounts
Unknown Internet Targets
────────────────────────────

Always stay inside the authorized boundary.

AI labs may eventually use:

  • API keys

  • Cloud credentials

  • Tokens

  • SSH keys

  • Service accounts

Treat all of them as secrets.

Never:

Paste credentials into screenshots
Commit them to Git
Share them in public repositories
Store them in documentation
Post them in forums
Reuse production credentials

Prefer dedicated lab credentials with minimal permissions.

Where possible:

Production Account
β‰ 
Learning Lab Account

A separate sandbox reduces the impact of mistakes.

For example:

Personal Learning Cloud Account
β”‚
β”œβ”€β”€ Lab IAM Users
β”œβ”€β”€ Lab Resources
β”œβ”€β”€ Lab Logs
└── Temporary Experiments

Do not use an employer’s production environment for personal training.

Even a lab should reinforce good security practices.

Instead of granting:

Administrator Access

everywhere, try to understand what permissions are actually required.

This helps you learn IAM while improving your lab security.

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.

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 Required

This makes experimentation safer.

Use this checklist.

  • Operating system ready

  • Sufficient storage available

  • Browser installed

  • Visual Studio Code installed

  • Git installed

  • Python installed

  • Python virtual environment tested

  • Docker installed

  • Docker test container runs successfully

  • curl available

  • API testing client available

  • Basic JSON understood

  • Lab directories created

  • Evidence folders created

  • Threat modeling folder created

  • Runbook folder created

  • Notes template created

  • Findings template created

  • .gitignore created

  • Secrets excluded from Git

  • Lab credentials separated where possible

  • Testing boundaries understood

If these are complete, your core environment is ready.

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.md

You do not need to fill every directory immediately.

The structure is there so the lab can grow with you.

At the beginning:

Workstation
+
Python
+
Git
+
Docker

Later:

AI Applications
+
LLM APIs
+
RAG
+
Vector Databases

Then:

AI Agents
+
Cloud Infrastructure
+
Security Monitoring
+
Threat Modeling

Eventually:

Enterprise AI Security Environment

The lab grows as your skills grow.

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.

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
↓
Document

This environment will become the foundation for your labs and enterprise projects throughout the learning path.

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.

➑️ 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