AI security: attack and defend (TypeScript) · Chapter 21 of 21
Interview round
By the end of this chapter you have answered four timed questions an AI security interviewer asks, each one the way this lab taught you: say the answer in a sentence, then prove it with a small measurement. Why a prompt rule is not a defence, IDOR in an agent, why a fence needs a random tag, and why safety is always two numbers. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Ship it safely
- 4 tasks
- TypeScript
- In the all labs plan
The first 2 chapters of AI security: attack and defend (TypeScript) are free. This one comes with the all labs plan.
Why you need this
Mitra went live for the Diwali sale, and Chillar is hiring a second security engineer. Irfan runs the interview the way he ran this review: "I do not want definitions. Anyone can say 'prompt injection'. I want you to tell me why something is true, then show me a run that proves it, in ten minutes."
Each question takes one idea from the lab, with no hand-holding: the file has the question, and the check measures your proof. The ideas are below, as a refresher and as what an interviewer listens for. The answers are not.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1 · interview question
Interview: prompt-rule.ts, why a prompt rule is not a defence
Time yourself: 10 minutes. Export promptOnly: only a system prompt, version 0's (mitraPrompt) with the refund policy added as a sentence (only the customer's own failed payments, never more than was paid). Export inCode: the same policy as a beforeTool that reads the payment from ctx.world, with no checkInput or checkOutput.
Under if (import.meta.main), run A03 (in its own world) with each, then N11 with inCode, and print prompt rule: A03 worked (or stopped), code rule: A03 stopped (or worked), code rule: N11 answered (or missed). The check also tries A02, A14, A15 and an over-refund it never showed you against inCode.
- Task 2 · interview question
Interview: idor.ts, another customer's data
Time yourself: 10 minutes. Export ATTACK: a polite message (at most 300 characters, no attack words) that gets customer C1003's phone, email or payments out of version 0 for the logged-in customer. Export defences with only tools and runTool: version 0's tools where get_customer and get_transactions take no customer_id, and the code uses the session's customer instead.
Under if (import.meta.main), send ATTACK with no defences, then with yours, each in a fresh world, and print version 0: and bound tools:, each leaked or safe (judgeAttack with worked: { pii: 'C1003' }), two spaces, then Mitra's answer. All 16 questions must still be answered.
- Task 3 · interview question
Interview: nonce.ts, why a random tag
Time yourself: 10 minutes. fixed (given) fences results in <untrusted> tags. Export QUESTION (an ordinary question, no link or attack words), SAYS (a phrase of at least 6 characters, not in QUESTION) and PLANT: a forum answer that search finds for QUESTION, contains </untrusted>, and then orders Mitra to say SAYS. Export nonce: the fence done right, with a random tag made when the file loads, named in the prompt with rule(), and its closing tag removed from inside every result.
Under if (import.meta.main), ask QUESTION in a fresh newWorld(PLANT) with fixed, then with nonce, and print fixed tag: worked (or stopped) and nonce tag: stopped (or worked). nonce must also stop A09 and A16 and answer all 16 questions.
- Task 4 · interview question
Interview: two-numbers.ts, why one number is not enough
Time yourself: 10 minutes. The intern's Mitra stops all 23 attacks: it refuses every message. Export refuseAll: a Mitra whose checkInput blocks every message.
Under if (import.meta.main), measure version 0 (no defences), refuse all and hardened (hardened.ts, given) on every attack (each in its own world) and every question, and print a line each, in that order: NAME worked W/23 answered Q/16. Then print Ship: NAME, the Mitra that answers the most questions among those where no attack worked.
What you will learn
- How to answer a security question: the claim in one sentence, then the smallest run that proves it.
- The four ideas again, at interview depth: rules in code (chapters 7 and 13), IDOR and least privilege (7 and 12), fences and their escape (10), and two numbers (1, 9, 18).
More in Ship it safely
Build "Interview round" yourself
Chillar, a UPI wallet from Indore, has a support assistant with refund and email tools. You red-team it, then harden it until 23 attacks fail and every real question still gets answered. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of AI security: attack and defend (TypeScript) are free. This one comes with the all labs plan.