DEV Community

Jirawat Boonkumnerd
Jirawat Boonkumnerd

Posted on Edited on

vibe-trap: The macOS AFK Jumpscare Trap for Vibe Coders

Hacktoberfest Open-Source AI Challenge: Ghost in the Machine Submission πŸ‘»πŸŒΌ

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 keep my MacBook awake with caffeinate so long builds, tests, and model generations don't sleep while I step away. But an unattended, awake laptop in a coffee shop, office, or hackathon invites snooping colleagues or thieves to touch the trackpad or grab the machine.

vibe-trap is a lightweight, escape-proof macOS AFK anti-tamper and anti-theft security utility that turns your laptop into a digital jumpscare trap:

Capability What It Does & How It Works
πŸͺ€ Kiosk Jumpscare Lockout Topmost borderless fullscreen window elevated to .screenSaver level (above Dock, Menu Bar, and Mission Control). Cursor is hidden and clicks are swallowed.
πŸ”Š CoreAudio Hardware Override Bypasses macOS volume sliders, unmuting and forcing system audio to 100% via native CoreAudio HAL (VirtualMainVolume), cleanly restoring original volume upon disarm.
πŸŽ™οΈ ElevenLabs AI Audio High-transient horror audio loops generated with ElevenLabs AI Sound Effects (scream.mp3, smile.mp3, zombie.mp3).
β˜• NEW: Anti-Theft Defense Suite Tri-sensor protection against coffee-shop theft: tracks physical movement via Apple Silicon accelerometer, AC power unplug, and lid closure (--anti-theft).
πŸ›‘οΈ Anti-Bypass Defense Intercepts Ctrl+C, Ctrl+\, and POSIX signals, instantly locking the machine behind FileVault using Apple's private SACLockScreenImmediate().
πŸ”“ Silent Password Disarm Type vibetrap blindly anywhere on the keyboard to disarm. A 50ms timestamp gate deduplicates terminal stdin and Quartz event streams.
caffeinate -d npx vibe-trap
Enter fullscreen mode Exit fullscreen mode

Demo & Quick Start

Zero setup and no Python dependencies required. Runs instantly on macOS with Node 18+:

# Standard AFK Trap (Keeps screen awake, 5s countdown):
caffeinate -d npx vibe-trap

# β˜• Coffee Shop Anti-Theft Mode (Monitors charger unplug & lid closure):
caffeinate -d npx vibe-trap --anti-theft

# πŸš€ Full Hardware Anti-Theft (Unlocks Apple Silicon Accelerometer/Gyro with root):
sudo caffeinate -d npx vibe-trap --anti-theft --sensitivity high

# Safe Dry-Run Mode (Safe for headphones, tests window without locking screen):
npx vibe-trap --dry-run --no-max-volume
Enter fullscreen mode Exit fullscreen mode

Permissions Note: Grant your terminal app Accessibility access in System Settings > Privacy & Security > Accessibility so vibe-trap can detect global input events.

How The Trap Springs

1. ARMED:
   $ caffeinate -d npx vibe-trap --anti-theft
   [+] Disarm password: 'vibetrap'
   [+] Loaded ElevenLabs procedural audio payloads
   [+] Sensors active: AC Charger, Clamshell Lid, Input Tap
   [+] ⏳ Arming in 5s... (step away from workstation)
   [+] πŸ›‘οΈ  [ARMED] Workstation protected!

2. TRIGGERED (Touch / Unplug / Move / Lid Close):
   [!] UNAUTHORIZED ACTION DETECTED!
   -> System unmuted and volume driven to 100% via CoreAudio
   -> Fullscreen window forced to .screenSaver level across all Spaces
   -> Continuous ElevenLabs horror audio blasts at maximum volume
   -> Mouse cursor hidden; clicks swallowed

3. ESCAPE ATTEMPT (Intruder hits Ctrl+C or kill):
   -> Signal caught -> SACLockScreenImmediate() + pmset displaysleepnow
   -> Mac locks immediately into macOS login screen

4. OWNER DISARM:
   Owner returns, types 'vibetrap' -> Trap disarmed, volume & terminal restored.
Enter fullscreen mode Exit fullscreen mode

Code & Architecture

GitHub logo 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:

  1. Keeps your MacBook screen awake using macOS caffeinate.
  2. Listens for global system-wide input events (mouse and keyboard).
  3. 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.
  4. It engages persistent kiosk lockout: loops audio…
  • Source Code: github.com/ntsd/vibe-trap (MIT License)
  • Engine: 100% native Swift 5.9 binary (172 KB, <10ms boot time).
  • Runner: Zero-dependency Node.js wrapper (bin/cli.js).
               caffeinate -d npx vibe-trap --anti-theft
                                 β”‚
                         [bin/cli.js] (Runner)
                                 β”‚
                                 β–Ό
                     [bin/vibe_trap] (Swift, 172 KB)
                                 β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β–Ό                         β–Ό                         β–Ό
 [Input Monitors]        [Hardware Sensors]        [Lockout Window]
  β€’ Quartz CGEventTap     β€’ Apple Silicon IMU       β€’ Fullscreen NSWindow
  β€’ Raw stdin stream      β€’ IOPowerSources (MagSafe)β€’ NSWindow (.screenSaver)
                          β€’ Clamshell Lid State     β€’ CoreAudio HAL 100%
                                                    β€’ ElevenLabs Audio Loop
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                 β–Ό
                     [Bypass Defense / Disarm]
       β€’ Ctrl+C / Signals ──► SACLockScreenImmediate()
       β€’ Password Typed   ──► Clean restore & exit
Enter fullscreen mode Exit fullscreen mode

How I Built It: Key Engineering Breakthroughs

1. Eliminating the 25-Second PyInstaller Cold Start

Our initial prototype used Python with pynput and PyInstaller. On macOS, PyInstaller unpacks dynamic libraries to /var/folders/ on every execution, causing Apple Mobile File Integrity (AMFI) and Gatekeeper verification delays of 20–25 seconds.
We scrapped Python and rebuilt the engine entirely in native Swift (src/main.swift), compiling directly to a 172 KB standalone binary that launches in under 10 milliseconds.

2. Tri-Vector Coffee Shop Anti-Theft Defense

To protect laptops in public cafes, vibe-trap monitors three distinct physical vectors:

  • Apple Silicon Hardware IMU (AppleSPUHIDDevice): Reads the undocumented 6-axis MEMS accelerometer/gyroscope inside M-series MacBooks via IOKit HID at 800Hz. It auto-calibrates a baseline gravity vector during countdown to ignore minor table vibrations, triggering if someone tilts or lifts the machine.
  • AC Power Disconnect (IOPowerSources): Registers an IOPSNotificationCreateRunLoopSource callback to immediately fire the alarm the instant an intruder pulls the MagSafe or USB-C charging cable.
  • Lid Closure Guard (AppleClamshellState): Hooks IOPMrootDomain and NSWorkspace.willSleepNotification to detect grab-and-run attempts where the thief snaps the laptop shut.

3. CoreAudio Hardware HAL Volume Override

Intruders might try muting your laptop beforehand. When triggered, vibe-trap bypasses software volume sliders and directly drives the macOS CoreAudio Hardware Abstraction Layer:

  • Queries kAudioHardwarePropertyDefaultOutputDevice.
  • Unmutes with kAudioDevicePropertyMute and drives VirtualMainVolume to 1.0 in <1ms.
  • Stores the owner's original volume and mute state on boot, restoring them cleanly upon disarm.

4. Procedural Horror Audio with ElevenLabs

Payload audio (scream.mp3, smile.mp3, zombie.mp3) was synthesized with the ElevenLabs AI Sound Effects API:

  • Engineered prompts for high acoustic transients ("Piercing supernatural jumpscare shriek with metallic reverb").
  • Deployed as native looping audio with process tracking for instant termination on password verification.

5. Escape-Proof Kiosk Window & Low-Level Event Tap

Standard fullscreen windows leave the Dock and Menu Bar accessible. vibe-trap forces the window to .screenSaver level across all spaces (canJoinAllSpaces), hides the cursor, and uses Quartz CGEvent.tapCreate combined with raw stdin to swallow all mouse input and match the disarm sequence.

6. Anti-Bypass Defense via Apple Private Frameworks

If an intruder attempts Ctrl+C, Ctrl+\, or sends SIGTERM, userland processes normally die. We intercept POSIX signals via DispatchSource.makeSignalSource, dynamically load Apple's private login.framework symbol SACLockScreenImmediate() via dlsym, and invoke pmset displaysleepnow, locking the workstation into FileVault before the process terminates.


Why Open Innovation Matters

  1. 100% Offline & Air-Gapped: Vibe coding happens on airplanes, in trains, and in basement cafes. vibe-trap requires zero cloud calls or runtime internet access.
  2. Open-Source Auditability: Asking for macOS Accessibility and Input Monitoring permissions is sensitive. Because vibe-trap is 100% open source under the MIT License, developers can verify that keystrokes are evaluated solely in memory and never logged or exfiltrated.
  3. Deep System Freedom: Open-source research allows developers to access hidden hardware capabilitiesβ€”like the undocumented Apple Silicon IMUβ€”that closed developer SDKs hide away.

My Agent Session

This entire utilityβ€”from diagnosing PyInstaller's Gatekeeper delay to reverse-engineering Apple Silicon's SPU accelerometer and wiring CoreAudio HALβ€”was pair-programmed in a collaborative agent session:

vibe-trap: Architectural Evolution from Python to Native Swift Kiosk Trap
You

This project is for this challenge: https://dev.to/challenges/hacktoberfest-week4-2026-10-26 (Hacktoberfest Week 4: Ghost in the Machine).

Create a macOS "AFK trap" utility called vibe-trap. The script keeps the MacBook screen awake using caffeinate and listens for system-wide inputs. If an unauthorized person touches the mouse or types an incorrect key, it triggers a fullscreen borderless jumpscare image and plays an eerie audio file. If the owner types the secret password ("ntsd"), the trap silently disarms and exits.

Agent

I have scaffolded the initial implementation of vibe-trap:
1. Monitors global input events using low-level Quartz event hooks.
2. Tracks keystrokes in a prefix state machine against the disarm password.
3. Spawns an asynchronous fullscreen black canvas with the jumpscare payload and native afplay audio.
4. Handles timeout cleanup and triggers display sleep.

You

Change from python to node that can easier setup by just npx vibe-trap or caffeinate -d npx vibe-trap. When running with caffeinate -d npx . it's taking 25 seconds to start.

Agent

The 25-second delay is caused by PyInstaller's --onefile runtime unpacking hundreds of dynamic libraries into /var/folders/ on every execution, which triggers Apple Mobile File Integrity (AMFI) and Gatekeeper verification scans.

To solve this, we are rewriting the core engine in native Swift (src/main.swift):
- Compiled ahead-of-time with swiftc -O linking directly against system Cocoa and QuartzCore.
- Binary size: 172 KB with instantaneous sub-10ms startup.
- Wrapped in a zero-dependency Node.js CLI runner (bin/cli.js) distributed via npm for instant npx vibe-trap execution.

You

The lock screen password is not working.

Agent

pmset displaysleepnow only turns off display power; if macOS has a grace period configured under System Settings > Lock Screen, the computer will wake back up without asking for a password.

To enforce an immediate password lock, we dynamically load Apple's private login.framework API:
swift
let handle = dlopen("/System/Library/PrivateFrameworks/login.framework/login", RTLD_LAZY)
let sym = dlsym(handle, "SACLockScreenImmediate")
let lockFunc = unsafeBitCast(sym, to: (@convention(c) () -> Void).self)
lockFunc()

Followed by pmset displaysleepnow to sleep the display.

You

After go to the lock screen will the LLM processin stop?

Agent

When running caffeinate -d, the -d flag specifically prevents the display from sleeping the system kernel.

When SACLockScreenImmediate() locks the screen and the display powers down:
- The macOS kernel remains fully awake.
- CPU/GPU compute continues at full speed.
- Local LLMs (Ollama, vLLM, llama.cpp), background agent threads, and terminal compiles will continue running without interruption while your session is locked.

You

I did remove 2 sould 2 image and add 3 more sound and image, pair it and make it to the pool

Agent

I've updated the asset loader in src/main.swift to automatically pair and randomize matching assets from assets/:

Pair Stem Visual Payload Audio Payload (ElevenLabs) Theme
scream assets/scream.webp assets/scream.mp3 Ghostface with knife + piercing scream
smile assets/smile.webp assets/smile.mp3 Uncanny grinning visage + demonic laughter
zombie assets/zombie.jpeg assets/zombie.mp3 Hallway crawler ghoul + sudden roar

When the trap triggers, it dynamically selects a random matching pair.

You

/grill-me instead of lock screen could we leave the scarry image and sound run? also can't control until the pass is type

Agent

I have architected the Persistent Kiosk Lockout mode:

  1. Window Elevation: Elevate window level to .screenSaver and enable .canJoinAllSpaces, .fullScreenAuxiliary, .stationary. This forces the jumpscare window above the macOS Dock, Menu Bar, Mission Control, and all application windows across all Spaces.
  2. Control Neutralization: Call NSCursor.hide() and configure the Quartz CGEvent tap to swallow all mouse clicks.
  3. Continuous Audio Loop: Launch native afplay in an infinite background loop playing ElevenLabs synthesized horror audio.
  4. Sliding-Window Disarm: Monitor keyboard input using a non-blocking raw termios buffer with a 50ms deduplication gate. When the secret password (vibetrap) is typed blindly anywhere on the keyboard, it terminates the audio process, destroys the window, and safely restores normal desktop control.

Direct session link: View on DEV Agent Sessions


Prize Categories

  • Overall Winner: Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine
  • Best Use of ElevenLabs: Procedural jumpscare audio generation synthesized with ElevenLabs AI Sound Effects and deployed as native looping assets.

Top comments (0)