This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine
What I Built
When vibe coding with autonomous agents, I always run caffeinate so background builds, tests, and downloads never sleep while I step away. But leaving an unattended, awake MacBook in a cafe, office, or hackathon invites snooping coworkers to touch the trackpad.
So I built vibe-trapβa lightweight macOS AFK anti-tamper security utility that turns your laptop into a digital jumpscare trap:
- πͺ€ The Trap: Keeps your screen awake. After a 5-second countdown, the second an unauthorized hand touches the mouse or types an incorrect key, it locks into a fullscreen
.screenSaverkiosk and blasts looping ElevenLabs AI horror audio at full volume. - π Hardware Volume Escalation: Instantly unmutes and forces macOS system audio to 100% via CoreAudio hardware services (with automatic volume restoration upon disarm).
- π‘οΈ Anti-Bypass Lock: If the intruder tries
Ctrl+C,Ctrl+\, or termination signals to escape, it immediately triggers Apple's privateSACLockScreenImmediate()to lock macOS behind the system login. - π Silent Disarm: Type
vibetrapblindly anywhere on the keyboard to disarm and resume coding.
caffeinate -d npx vibe-trap
Demo
Quick Start
No Python environment or compilation needed. Runs instantly on macOS with Node 18+:
# Keep screen awake and arm the trap (5s countdown by default):
caffeinate -d npx vibe-trap
# Customize countdown (e.g. 10 seconds to step away):
caffeinate -d npx vibe-trap --countdown 10
# Safe dry-run mode (safe for headphones, skips screen lock):
npx vibe-trap --dry-run --no-max-volume
Tip β Keep Awake with Lid Closed (Clamshell Mode):
If you close your MacBook lid, macOS sleeps by default. To keep processes and traps running with the lid shut:# Disable sleep on lid close: sudo pmset -a disablesleep 1 # Re-enable normal sleep behavior later: sudo pmset -a disablesleep 0
macOS Permissions Setup
Because vibe-trap monitors global input events across macOS, you just need to allow your terminal application in System Settings > Privacy & Security > Accessibility:
The Interaction Flow
1. VIBE CODER ARMS TRAP:
$ caffeinate -d npx vibe-trap
[+] Disarm sequence armed: 'vibetrap'
[+] Loaded jumpscare asset pairs (ElevenLabs audio + visual payloads)
[+] β³ Arming touch sensor in 5s... (step away from mouse & keyboard)
[+] π‘οΈ [ARMED] Sensors active! Display kept awake. Listening for tampering...
2. INTRUDER TOUCHES TRACKPAD OR PRESSES A KEY:
[!] UNAUTHORIZED INPUT DETECTED!
-> System audio unmuted and forced to 100% via CoreAudio
-> Window level elevated to .screenSaver (above Dock, Menu Bar, Spaces)
-> Mouse cursor hidden; clicks swallowed
-> Continuous ElevenLabs horror audio loop blasts at full volume
3. INTRUDER ATTEMPTS BYPASS:
Intruder hammers Ctrl+C or kill signals
-> POSIX Signal Trap fires -> SACLockScreenImmediate() + pmset displaysleepnow
-> Mac locks immediately into FileVault login
4. OWNER DISARM:
Owner returns, types "vibetrap"
-> [β] PASSWORD VERIFIED! Trap cleanly disarmed. Original volume restored. Terminal restored.
Code
ntsd
/
vibe-trap
macOS AFK anti-tamper & jumpscare trap utility. Keeps screen awake, locks workstation on unauthorized touch.
πͺ€ vibe-trap
macOS AFK Anti-Tamper & Jumpscare Utility
Keeping your MacBook screen awake, watching for unauthorized hands, and springing the ultimate trap.
Built for the DEV Hacktoberfest 2026 Week 4 Challenge: Ghost in the Machine.
β‘ Overview
When you're vibe coding with autonomous agents, long builds, downloads, and model generations mean you always run caffeinate to keep your MacBook awake while stepping away. But an unattended, awake laptop invites snooping coworkers or friends to touch your trackpad or browse your terminal history.
vibe-trap is a lightweight macOS AFK security trap that:
- Keeps your MacBook screen awake using macOS
caffeinate. - Listens for global system-wide input events (mouse and keyboard).
- If an unauthorized person touches the mouse (any click) or types an incorrect key, it immediately launches a borderless, topmost, fullscreen jumpscare/meme window and blasts an eerie audio payload using native
afplay. - It engages persistent kiosk lockout: loops audioβ¦
vibe-trap is open source under the MIT License:
- Repository: github.com/ntsd/vibe-trap
-
Engine: Swift 5.9 native binary (172 KB, <10ms startup), Apple AppKit, QuartzCore (
CGEvent), CoreAudio / AudioToolbox, POSIX Dispatch Sources. -
CLI Runner: Zero-dependency Node.js wrapper (
bin/cli.js).
Architecture
caffeinate -d npx vibe-trap
β
[bin/cli.js] (Lightweight runner)
β
βΌ
[bin/vibe_trap] (Native Swift Binary, 172 KB)
β
ββββββββββ΄βββββββββ¬ββββββββββββββββββββ
βΌ βΌ βΌ
[Quartz HID Tap] [Raw Stdin Buffer] [CoreAudio Hardware]
CGEvent.tapCreate termios non-blocking VirtualMainVolume
Catches any click 50ms deduplication Unmutes & sets to 100%
β β β
βββββββββββββββββββ΄ββββββββββββββββββββ€
βΌ βΌ
[Tamper Detected] [Owner Disarms]
β’ System Volume -> 100% β’ Types 'vibetrap'
β’ NSWindow.Level .screenSaver β’ Audio stopped
β’ NSCursor.hide() β’ Volume restored to original
β’ Loop ElevenLabs horror audio β’ Window closed & exits cleanly
β’ Ctrl+C / Signals -> SACLockScreenImmediate()
How I Built It
To make vibe-trap instantaneous and escape-proof, I addressed six core system challenges:
1. Eliminating the 25-Second PyInstaller Cold Start
Our initial prototype used Python with pynput and PyInstaller. On macOS, PyInstaller unpacks dynamic libraries into /var/folders/ on every run, triggering Apple Mobile File Integrity (AMFI) and Gatekeeper verification that took 20β25 seconds to boot.
We scrapped Python and rewrote the engine in native Swift (src/main.swift):
- Direct compilation with
swiftc -Olinking macOS systemCocoaandQuartzCore. - Binary size: 172 KB. Cold start: under 10 milliseconds.
2. Procedural Horror Audio with ElevenLabs
Payload audio (scream.mp3, smile.mp3, zombie.mp3) was synthesized using the ElevenLabs AI Sound Effects API:
- Prompts engineered for high dynamic range and abrupt acoustic transients ("Piercing supernatural jumpscare shriek with metallic reverb").
- Played through macOS
NSSound/afplayin an infinite background loop with PID tracking for instant termination upon disarm.
3. Hardware-Level Volume Override & Restoration (CoreAudio)
Intruders or colleagues might attempt to mute the laptop beforehand to be sneaky. When triggered, vibe-trap bypasses high-level UI sliders and uses Apple's native CoreAudio HAL to unmute and force output volume to 100%:
- Queries default output device via
kAudioHardwarePropertyDefaultOutputDevice. - Unmutes with
kAudioDevicePropertyMuteand driveskAudioHardwareServiceDeviceProperty_VirtualMainVolumeto1.0in<1ms. - Stores original volume on startup and gracefully restores the owner's exact volume setting upon disarm.
4. Escape-Proof Kiosk Window (.screenSaver Level)
Standard fullscreen macOS windows leave the Dock and Menu Bar accessible. vibe-trap elevates the window above the desktop manager:
window.level = .screenSaver
window.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary, .stationary]
NSCursor.hide() // Neutralizes cursor navigation
5. Low-Level Quartz HID Event Tap & Stdin Deduplication
To catch unauthorized inputs globally across macOS:
-
CGEvent.tapCreatemonitors.leftMouseDown,.rightMouseDown, and.otherMouseDownacross the system. - Terminal raw mode (
termiosnon-blockingVMIN=0, VTIME=0) monitors keystrokes. - A 50ms timestamp deduplication gate prevents dual-capture between the event tap and
stdin, feeding a sliding-window string validator for the disarm password (vibetrap).
6. Anti-Tamper Bypass Defense (Signals & Apple Private Frameworks)
If an intruder tries Ctrl+C (0x03), Ctrl+\ (0x1c), or SIGTERM, userland processes normally terminate, leaving the machine exposed.
We intercepted POSIX signals using DispatchSource.makeSignalSource:
let sigint = DispatchSource.makeSignalSource(signal: SIGINT, queue: .main)
sigint.setEventHandler { enforceScreenSleepLock() }
sigint.resume()
enforceScreenSleepLock() dynamically resolves Apple's private login.framework symbol SACLockScreenImmediate() via dlsym and invokes pmset displaysleepnow, locking the workstation before the process exits.
Why Does Open Innovation Matter?
-
Air-Gapped, Zero-Cloud Reliability: Vibe coding happens anywhereβairplanes, cafes, and basement venues with spotty Wi-Fi.
vibe-trapoperates completely offline with zero runtime cloud dependencies. -
Open-Source Auditability for Input Access: Requesting macOS Accessibility and Input Monitoring permissions is sensitive. Because
vibe-trapis 100% open source under the MIT License, developers can verify that keystrokes are evaluated solely in memory and never logged or exfiltrated. -
Frictionless Developer Distribution: Combining native Swift binaries with
npxallows any macOS developer to secure their workstation without complex dependencies.
My Agent Session
This entire utilityβfrom the initial scaffold, through diagnosing PyInstaller's 25-second Gatekeeper unpack delay, to dynamically loading Apple's private SACLockScreenImmediate() API and architecting persistent kiosk lockoutβwas pair-programmed in a collaborative agent session:
Direct session link: View on DEV Agent Sessions
The Spirit of It
I had an autonomous agent vibe coding a refactor on my desk with caffeinate -d npx vibe-trap active while I grabbed an espresso. A colleague stopped by, glanced at the streaming terminal logs, and tapped the trackpad to scroll up.
Instantly, the Ghostface jumpscare took over both monitors, volume jumped to 100%, and ElevenLabs' screech echoed across the quiet room. My colleague jumped backward, panicked, reached over to mash Ctrl+C, and watched the screen instantly go black and lock into FileVault.
When I returned, I typed vibetrap on the login screen, unlocked macOS, and found my agent finishing its tests untouched.
Prize Categories
- Overall Winner: Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine
-
Best Use of ElevenLabs: Procedural horror audio generation (
scream.mp3,smile.mp3,zombie.mp3) synthesized with ElevenLabs AI Sound Effects and deployed as native looping payload assets.

Top comments (0)