Instant Guardian Prison

Build an automated guardian sentry in Minecraft that detects approaching hostile mobs and traps them in an instant iron bar cage with commands.

Java EditionMini-games & UtilitiesMedium24 commandsTested on a real 26.2 & 26.3 server
An elder guardian turret traps a hostile mob inside a suddenly generated iron bar cage. Download the GIF Video & GIF © www.9minecraft.net

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.

1. Setup - type these once 8 commands

  1. /scoreboard objectives add c9_timer dummy
  2. /scoreboard players set #sentry c9_timer 0
  3. /fill ~-2 ~-1 ~-2 ~2 ~-1 ~2 minecraft:dark_prismarine
  4. /fill ~-1 ~-1 ~-1 ~1 ~-1 ~1 minecraft:sea_lantern
  5. /setblock ~ ~ ~ minecraft:prismarine_wall
  6. /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]}}
  7. /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}]}
  8. /summon minecraft:marker ~4 ~ ~ {Tags:["c9_clean","c9_cage"]}

2. Loop - one repeating command block each (Always Active) 16 commands

  1. /scoreboard players add #sentry c9_timer 1
  2. /execute as @e[tag=c9_core] at @s run tp @s ~ ~ ~ ~6 ~
  3. /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}]}
  4. /execute if score #sentry c9_timer matches 2..40 as @e[tag=c9_intruder] at @s run tp @s ~-0.125 ~ ~ 90 0
  5. /execute as @e[tag=c9_eye] at @s facing entity @e[tag=c9_intruder,limit=1] eyes run tp @s ~ ~ ~ ~ ~
  6. /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
  7. /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
  8. /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
  9. /execute if score #sentry c9_timer matches 40 at @e[tag=c9_cage] run fill ~-1 ~-1 ~-1 ~1 ~-1 ~1 minecraft:lodestone
  10. /execute if score #sentry c9_timer matches 40 at @e[tag=c9_cage] run fill ~-1 ~ ~-1 ~1 ~2 ~1 minecraft:iron_bars outline
  11. /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]
  12. /execute if score #sentry c9_timer matches 40 at @e[tag=c9_cage] run summon minecraft:lightning_bolt ~ ~3 ~
  13. /execute if score #sentry c9_timer matches 115 at @e[tag=c9_cage] run fill ~-1 ~ ~-1 ~1 ~3 ~1 minecraft:air
  14. /execute if score #sentry c9_timer matches 115 at @e[tag=c9_cage] run fill ~-1 ~-1 ~-1 ~1 ~-1 ~1 minecraft:grass_block
  15. /execute if score #sentry c9_timer matches 115 run kill @e[tag=c9_intruder]
  16. /execute if score #sentry c9_timer matches 130 run scoreboard players set #sentry c9_timer 0

How it works

Frames from the test run

Instant Guardian Prison - frame 1Instant Guardian Prison - frame 2Instant Guardian Prison - frame 3

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.

Build it in your world

  1. Stand at the center of a flat open area where you want the sentry tower to sit.
  2. Run each command from the Setup list in chat once to build the prismarine pedestal, rotating core, and cage target marker.
  3. Place a Repeating Command Block set to Always Active underneath the stage and paste the first Loop command into it.
  4. Attach a line of Chain Command Blocks (Always Active, Unconditional) to the repeating block and paste the remaining Loop commands in order.
  5. Watch the armored husk spawn, walk into the cyan scan zone, and get locked inside the lightning-charged iron prison.

Use it with real players

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.

Remove it again 4 commands

  1. /scoreboard objectives remove c9_timer
  2. /kill @e[tag=c9_clean]
  3. /fill ~-2 ~ ~-2 ~6 ~4 ~2 minecraft:air
  4. /fill ~-2 ~-1 ~-2 ~6 ~-1 ~2 minecraft:grass_block

FAQ

Why use an invisible Elder Guardian inside the sea lantern core?

When 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.

Can trapped mobs break out of the iron bar cage?

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.

Commands used

/execute/fill/kill/particle/scoreboard/setblock/summon/tp

Similar creations

Join 9Minecraft News & Guides