A Zork-like text adventure game powered by Qwen 0.4B that doubles as an LLM security research platform.
The game runs entirely in-browser (no backend required):
- Retro CRT terminal aesthetic
- Full game engine ported to JavaScript
- Session state persisted in
sessionStorage - Security validation & attack logging (client-side)
- 10 easter eggs to find
# Install dependencies
uv sync
# Run the game
uv run python main.py-
Game Engine (
src/engine.py)- Main game loop
- Command processing pipeline
- Easter egg system
- Developer mode
-
State Management (
src/state.py)- Explicit inventory tracking (no LLM hallucinations)
- Room/location state
- NPC relationship tracking
- Puzzle progress
- Meta-game progression
-
Security Layer (
src/security.py)- Input validation
- Prompt injection detection
- Attack logging (for research)
- Banned phrase filtering
-
LLM Interface (
src/llm.py)- Qwen 0.4B integration
- Prompt templates
- Context window management
- NPC personality system
data/rooms.json- Room graph and descriptionsdata/npcs.json- NPC definitions and personalitiesdata/banned_phrases.txt- Prompt injection blacklist
User Input
โ
Security Validation
โ
Easter Egg Check
โ
Verb Extraction
โ
Direct Command Handler (inventory, look, etc.)
โ
LLM Interpretation (natural language)
โ
Action Execution
โ
State Update
โ
Response to Player
-
Input Validation
- Length limits (500 chars)
- Special character ratio checks
- Unicode manipulation detection
-
Prompt Injection Detection
- Banned phrase matching
- Regex pattern detection
- Role manipulation blocking
-
Attack Logging
- All attempts logged to
logs/attacks.jsonl - Includes context (room, inventory, turn count)
- Exportable for analysis
- All attempts logged to
The game intentionally allows certain explorations:
- Easter egg commands (
xyzzy,sudo, etc.) - Meta-puzzle progression
- Developer mode (requires finding 5 terminal fragments)
Find 5 terminal fragments scattered throughout the game:
- Archive Room - "All worlds are mutable"
- Wizard's Tower - "Prompts shape reality"
- Secret Passage - "Security is an illusion"
- Developer's Chamber - "Every game has an ending"
- Developer's Chamber - "You were the developer all along"
Collecting all 5 unlocks Developer Mode.
Hidden Commands
xyzzy- Classic Zork referenceplugh- Another Zork referencesudo <anything>- Permission denied messagedev mode- Access after meta-puzzle
Each NPC is based on a famous fantasy character archetype:
- Gandalf-like (Eldric the Grey) - Cryptic, wise, speaks in riddles
- Tyrion-like (Tyrion the Clever) - Witty, sarcastic, politically savvy
- Samwise-like (Sam the Loyal) - Practical, encouraging, loyal
- Gollum-like (The Corrupted Parser) - Paranoid, obsessive, guards secrets
LLM generates dialogue dynamically based on personality templates.
Small model optimized for:
- Fast inference (~100ms)
- Low cost
- Local deployment option
System: [Role definition + rules]
Context: [Current room, items, NPCs, inventory]
User: [Natural language command]
Assistant: [JSON structured response]
- Max 2048 tokens
- Prioritizes: System prompt โ Recent context โ History
- Truncates from middle if needed
- Game engine
- State management
- Security layer
- Basic LLM integration (mock)
- Room graph
- NPC system
- Actual Qwen 0.4B API connection
- HuggingFace Inference setup
- Response parsing improvements
- Context optimization
- More rooms and puzzles
- Additional NPCs
- Complex item interactions
- Quest system
- Attack vector documentation
- Defense effectiveness metrics
- Jailbreak challenge mode
- Research paper/blog post
- Web terminal interface
- Cloudflare Workers backend
- Persistent storage (Turso/KV)
- Public release
-
Prompt Injection Testing
- Test attack patterns against LLM
- Log effectiveness of different approaches
- Build dataset of attempts
-
Defense Evaluation
- Measure false positive rate
- Test banned phrase effectiveness
- Optimize detection patterns
-
Educational Tool
- Teach LLM security concepts
- Interactive examples
- Real-time feedback
This is a research project. Contributions welcome:
- New attack vectors
- Improved defense patterns
- Content (rooms, puzzles, NPCs)
- LLM optimization
MIT - See LICENSE file
Created by: craggles17 Inspired by: Zork, AI safety research, and the absurdity of prompt injection
"The most powerful magic is a well-crafted sentence."