Build an automated guardian sentry in Minecraft that detects approaching hostile mobs and traps them in an instant iron bar cage with commands.
Arenas & Mini-gamesOceanWaterCyanBlueBlackPvPAdventure MapMap MakingBlock displaysSummoned mobsBlock building (fill/setblock/clone)Lightning boltsRotation math21+ commands
The Instant Guardian Prison is a defensive turret that watches over your base and traps intruders before they can reach you. An elder guardian eye hovers above a prismarine pedestal, sweeping the ground with a cyan detection ring until a hostile mob steps inside its perimeter.
The moment an intruder enters the scan zone, the sentry switches to red alert, fires a targeting beam, and drops a solid iron cage from the sky to lock the mob in place before neutralizing it and resetting for the next wave.
/scoreboard objectives add c9_timer dummy/scoreboard players set #sentry c9_timer 0/fill ~-2 ~-1 ~-2 ~2 ~-1 ~2 minecraft:dark_prismarine/fill ~-1 ~-1 ~-1 ~1 ~-1 ~1 minecraft:sea_lantern/setblock ~ ~ ~ minecraft:prismarine_wall/summon minecraft:block_display ~ ~1.5 ~ {Tags:["c9_clean","c9_core"],Glowing:1b,glow_color_override:65535,block_state:{Name:"minecraft:sea_lantern"},transformation:{left_rotation:[0.353f,0.353f,0.146f,0.853f],right_rotation:[0f,0f,0f,1f],scale:[0.7f,0.7f,0.7f],translation:[-0.35f,-0.35f,-0.35f]}}/summon minecraft:elder_guardian ~ ~1.5 ~ {Tags:["c9_clean","c9_eye"],NoAI:1b,Silent:1b,Invulnerable:1b,ActiveEffects:[{id:"minecraft:invisibility",amplifier:0,duration:-1,show_particles:0b}]}/summon minecraft:marker ~4 ~ ~ {Tags:["c9_clean","c9_cage"]}/scoreboard players add #sentry c9_timer 1/execute as @e[tag=c9_core] at @s run tp @s ~ ~ ~ ~6 ~/execute if score #sentry c9_timer matches 1 run summon minecraft:husk ~9 ~ ~ {Tags:["c9_clean","c9_intruder"],Glowing:1b,PersistenceRequired:1b,ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",count:1}]}/execute if score #sentry c9_timer matches 2..40 as @e[tag=c9_intruder] at @s run tp @s ~-0.125 ~ ~ 90 0/execute as @e[tag=c9_eye] at @s facing entity @e[tag=c9_intruder,limit=1] eyes run tp @s ~ ~ ~ ~ ~/execute if score #sentry c9_timer matches 1..40 run particle minecraft:dust{color:[0.0,1.0,0.8],scale:1.2} ~4 ~0.2 ~ 2.2 0.1 2.2 0 12/execute if score #sentry c9_timer matches 40..115 run particle minecraft:dust{color:[1.0,0.1,0.1],scale:1.6} ~ ~1.8 ~ 0.4 0.4 0.4 0 10/execute if score #sentry c9_timer matches 40..115 at @e[tag=c9_intruder] run particle minecraft:electric_spark ~ ~1.2 ~ 0.6 0.8 0.6 0.05 8/execute if score #sentry c9_timer matches 40 at @e[tag=c9_cage] run fill ~-1 ~-1 ~-1 ~1 ~-1 ~1 minecraft:lodestone/execute if score #sentry c9_timer matches 40 at @e[tag=c9_cage] run fill ~-1 ~ ~-1 ~1 ~2 ~1 minecraft:iron_bars outline/execute if score #sentry c9_timer matches 40 at @e[tag=c9_cage] run fill ~-1 ~3 ~-1 ~1 ~3 ~1 minecraft:dark_prismarine_slab[type=bottom]/execute if score #sentry c9_timer matches 40 at @e[tag=c9_cage] run summon minecraft:lightning_bolt ~ ~3 ~/execute if score #sentry c9_timer matches 115 at @e[tag=c9_cage] run fill ~-1 ~ ~-1 ~1 ~3 ~1 minecraft:air/execute if score #sentry c9_timer matches 115 at @e[tag=c9_cage] run fill ~-1 ~-1 ~-1 ~1 ~-1 ~1 minecraft:grass_block/execute if score #sentry c9_timer matches 115 run kill @e[tag=c9_intruder]/execute if score #sentry c9_timer matches 130 run scoreboard players set #sentry c9_timer 0setup #6 Summons a tilted, glowing sea lantern <code>block_display</code> above the prismarine wall to act as the rotating energy core of the sentry.loop #3 Spawns an armored husk at the edge of the platform at the start of each cycle so the sentry has an intruder to track and capture.loop #5 Rotates the invisible elder guardian to face the intruder every tick, making the guardian's floating eye track the mob as it walks closer.loop #10 Uses <code>/fill ... outline</code> around the cage marker to enclose the intruder in a hollow 3x3x3 box of iron bars the instant the timer hits tick 40.loop #13 Clears the iron bars and roof slab at tick 115 before resetting the cycle for the next intruder.


Recorded on our own test server: 60 frames at about 9.9 fps. Our image check saw: An elder guardian hovers over a prismarine and sea lantern pedestal, trapping a glowing husk mob inside a cage of iron bars and dark prismarine.
Commands, video and screenshots: tested and recorded by www.9minecraft.net © 9Minecraft. Sharing a video or screenshot? Please credit www.9minecraft.net.
To make the sentry trap any hostile mob dynamically instead of running on a fixed demo timer, remove the husk spawner and movement commands and replace the cage trigger with /execute at @e[tag=c9_eye] as @e[type=#minecraft:raiders,distance=..7,limit=1] at @s run fill ~-1 ~ ~-1 ~1 ~2 ~1 minecraft:iron_bars hollow. You can also target @a[distance=2..7,gamemode=survival] to trap trespassing players on a multiplayer server.
/scoreboard objectives remove c9_timer/kill @e[tag=c9_clean]/fill ~-2 ~ ~-2 ~6 ~4 ~2 minecraft:air/fill ~-2 ~-1 ~-2 ~6 ~-1 ~2 minecraft:grass_blockWhen an Elder Guardian is given the Invisibility effect, its body disappears while its glowing eye remains visible, creating a floating sentry eye that follows targets.
Standard mobs like zombies, husks, and skeletons cannot break iron bars or fit through a 3x3 hollow enclosure, keeping them contained until the sentry resets.
▶Mantis Shrimp Sonic-Cavitation Knockback ArenaArenas & Mini-gamesHard24 cmds
▶Nautilus Chambered Shell Spiral Gauntlet ArenaArenas & Mini-gamesHard26 cmds
▶Shattering Ice Floe Battle Royale ArenaArenas & Mini-gamesHard24 cmds
▶Blooming Lotus Petal Battle StageArenas & Mini-gamesHard24 cmds
▶Clockwork Orrery Tidal Wave ArenaArenas & Mini-gamesExpert24 cmds
▶Tornado Vortex Battle Royale ZoneArenas & Mini-gamesExpert19 cmds