Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Core / AI security fundamentals

AI security fundamentals cheat sheet

Set up (lesson 0)

TaskCommand or code
Make the lab foldermkdir -p ~/krlab/ai-security-fundamentals
Switch on the environment of "How AI works"source ~/krlab/how-ai-works/.venv/bin/activate
Prove that the lab workspython labcheck.py (the last line must say 3 of 3)
Which command to uselessons 2 and 3: python with the environment on; the others: python3

Use case and attack surface (lesson 1)

TaskCommand or code
The seven answers of a use casepurpose, objective, owner, success (a number), stop when, not for, human
Check a use casepython3 check_usecase.py (a file is an optional word)
The five places of attackdata, model, application, agent and tools, infrastructure
The three groups of writerstrusted, untrusted, third-party
Ask who can write to each assetpython3 assets.py (ASK means an untrusted or third-party writer)
Check a map for a missing layerpython3 assets.py assets-test.json | tail -2
Read JSON in Pythonjson.load(f)
Print the lines without a wordgrep -v word file

Lifecycle attacks (lesson 2)

TaskCommand or code
The stagesuse case, collect data, train, evaluate, deploy, operate
The floor of the gatetaken from the success answer of the use case
The three human pointshuman-in-the-loop (approves an action), human oversight (watches and may stop), human validation (checks a sample against reality)
Recall of each classrecall_score(y, model.predict(X), average=None)
Fixed random choice of positionsrng = np.random.default_rng(0), rng.choice(positions, n, replace=False)
Gate: fail when a class is weakweak = [d for d, r in enumerate(recalls) if r < floor]
Keep the test set outside the attacker's reachown storage, own owner, short access list

Evasion, poisoning, privacy (lesson 3)

TaskCommand or code
The three NIST AI 100-2 families (2025 edition)evasion, poisoning, privacy
Slope of the loss for each pixel (linear model)(model.predict_proba(X) - np.eye(10)[y]) @ model.coef_
Chosen-direction change of a given sizeX + size * np.sign(slope)
Keep pixels in rangenp.clip(images, 0, 16)
Confidence of the top answermodel.predict_proba(X).max(axis=1)
Cheap controlsreturn the label only, limit queries for each user, log the queries

Attack path with ATLAS (lesson 4)

TaskCommand or code
Tactic and techniquetactic = why, technique = how
Write the pathone line for each step: tactic, technique, asset, control
Check the pathpython3 check_path.py (a folder is an optional word)
Change text into a new filesed 's/old/new/' file > file.new && mv file.new file
Print lines 5 to 8sed -n 5,8p
Read a CSV in Pythoncsv.DictReader(open("file.csv"))

OWASP Top 10 for LLM Applications, 2025 edition (lesson 5)

TaskCommand or code
The ten risksPrompt Injection, Sensitive Information Disclosure, Supply Chain, Data and Model Poisoning, Improper Output Handling, Excessive Agency, System Prompt Leakage, Vector and Embedding Weaknesses, Misinformation, Unbounded Consumption
Test a secret in the promptpython3 test_leak.py
Test a planted instructionpython3 test_inject.py
Test output put in a pagepython3 test_html.py
Remove every link from an answerre.sub(r"https?://\S+", "[link removed]", answer)
Escape text for HTMLhtml.escape(answer)
Read a file as a list of linesopen("answers.txt").read().splitlines()

Threat model (lesson 6)

TaskCommand or code
The four questionswhat are we building, what can go wrong, what will we do, did we do a good job
Four kinds of untrusted textuser input, retrieved documents, tool results, model output
The rule for the fileevery flow that crosses a boundary has a threat, every threat has a control
Check flows and threatspython3 check_threats.py
Add a line to a fileecho 'T13,F9,...' >> threats.csv

Controls (lesson 7)

TaskCommand or code
The four kindsprevent, detect, respond, govern
A control must work outside the modelcolumn outside_model is yes; a sentence in the prompt is no
Find the gapspython3 check_controls.py
Add text to the end of a linesed '/^request-log/ s/$/ T2/' controls.csv > controls.new
Several edits in one sedsed -e '...' -e '...' file > file.new

Providers (lesson 8)

TaskCommand or code
Score a providerpython3 score.py vendor.json
Pointsyes = full weight, partial = half, no or unknown = none
VerdictsHOLD, REJECT, ACCEPT WITH CONDITIONS, ACCEPT
A critical item that is not yesHOLD, unless accepted_by names a person
Duties that stay with youdecide what data leaves, control access, treat output as untrusted, monitor, respond, prepare to leave

Public risk resources (lesson 9)

TaskCommand or code
MIT AI Risk RepositoryDomain Taxonomy: 7 domains, 24 subdomains; Causal Taxonomy: entity, intent, timing; written as 2.2
OWASP Machine Learning Security Top 10a draft with 2023 labels, ML01 to ML10; for a model that you train
CVE Program record (Common Vulnerabilities and Exposures)affected product, type or cause, description, public reference
CWECommon Weakness Enumeration: a numbered name for a type of weakness; a record should use one
CVE AI Working Groupdecides what counts as a CVE-able flaw in AI technology
Link threats and name watcherspython3 check_sources.py (a folder is an optional word)
Add a line to a fileecho 'A4,component,watcher' >> watch.csv

The security file (lesson 10)

TaskCommand or code
The five documentsassets.json, attack-path.csv, flows.csv and threats.csv, controls.csv, test-plan.csv
Check the whole file setpython3 check.py (a folder is an optional word)
Exit code of the checker0 = all rules pass, 1 = a rule fails
Copy several filescp ../kr-books/{a,b,c} .
Prove that a check can failbreak one value on purpose, run it, restore the file

The NIST AI Risk Management Framework (lessons 4, 6, 8 and 10)

FunctionQuestion
Governwho decides, who owns, who reviews
Mapwhat is the system, who is involved
Measurehow do we know that it works
Managewhich controls answer the risks

Safety habits