DEV Community

Jirawat Boonkumnerd
Jirawat Boonkumnerd

Posted 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 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 .screenSaver kiosk 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 private SACLockScreenImmediate() to lock macOS behind the system login.
  • πŸ”“ Silent Disarm: Type vibetrap blindly anywhere on the keyboard to disarm and resume coding.
caffeinate -d npx vibe-trap
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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:

Allow Terminal in macOS Accessibility Settings

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.
Enter fullscreen mode Exit fullscreen mode

Code

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…

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()
Enter fullscreen mode Exit fullscreen mode

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 -O linking macOS system Cocoa and QuartzCore.
  • 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 / afplay in 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 kAudioDevicePropertyMute and drives kAudioHardwareServiceDeviceProperty_VirtualMainVolume to 1.0 in <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
Enter fullscreen mode Exit fullscreen mode

5. Low-Level Quartz HID Event Tap & Stdin Deduplication

To catch unauthorized inputs globally across macOS:

  • CGEvent.tapCreate monitors .leftMouseDown, .rightMouseDown, and .otherMouseDown across the system.
  • Terminal raw mode (termios non-blocking VMIN=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()
Enter fullscreen mode Exit fullscreen mode

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?

  1. Air-Gapped, Zero-Cloud Reliability: Vibe coding happens anywhereβ€”airplanes, cafes, and basement venues with spotty Wi-Fi. vibe-trap operates completely offline with zero runtime cloud dependencies.
  2. Open-Source Auditability for Input Access: Requesting 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. Frictionless Developer Distribution: Combining native Swift binaries with npx allows 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:

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


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)