The /execute command changes the context a second command runs in, so you can control who runs it, where it runs, and under what conditions. This tutorial walks you through it with small examples you can copy into your own world. On Bedrock Edition, you need cheats enabled to use it, as the Microsoft Learn reference for Bedrock’s /execute command explains, while Java Edition requires operator permissions. Bedrock’s reference also lists context modifiers such as in, positioned, rotated, facing, align, and anchored, and Java Edition 26.3 (2026) added the if slots condition.
You will learn the difference between as and at, how target selectors like @a and @e narrow down which entities a command affects, and how if and unless conditions power redstone-style builds. Our guides cover both Java Edition and Bedrock Edition, and wherever a mechanic or permission differs, we say so. Keep timing in mind too. A repeat command block runs once per game tick, or 20 times per second, so a heavy command can cause lag.
Key Takeaways
- Every /execute line needs the word run, because that is where the setup ends and your command begins.
- Within an execute as, @s points at the entity running the command, not the player who typed it.
- Each player in an as @a line gets its own fork, so ten players on a gold block means ten separate teleports.
- Bedrock players should put heavy execute chains on an Impulse block wired to a lever, so each flip runs them once.
How Is the Execute Command Structured?
/execute changes the context a second command runs in. You decide who runs that command, where it runs, and what must be true before it runs. Think of /execute as the setup and the command after it as the action.
Every /execute line follows the same general shape: /execute [modifiers] run [command]. The modifiers sit between the word execute and the word run. You can chain several of them in any order that makes sense for your build, and run marks the point where the setup ends and your command begins.
To write one yourself, follow these steps:
- Type /execute to start the line.
- Add one or more modifiers, such as as @a, to set who runs the command.
- Type run to end the setup.
- Type the command you want to run, such as say hello.
Here is a short example. In Java Edition, type /execute as @a run say hello. In Bedrock Edition, type the same line. The @a selector picks every player, and as makes each of those players the one running the say command. Each player sends the word hello in chat, which makes this line a good first test.
Before you try it, check permissions. On Bedrock Edition, cheats must be enabled for the world, because /execute runs commands on behalf of entities. On Java Edition, you need operator permissions on the server or in the world, or the command will not work for you.
What Is the Difference Between as and at?

As changes who runs the command, and at changes where it runs from. Keeping those two words separate in your head prevents most beginner mix-ups.
The as modifier chooses the entity whose context the command runs in. Writing as @a makes every player the runner for the command that follows. The at modifier chooses a starting position. Writing at @s moves that starting point to the position of the entity you picked, so the command runs from that spot.
Here is a line that uses both: /execute as @a at @s run summon minecraft:pig ~ ~ ~. The as @a part makes each player the runner, and at @s places the starting point on that player. The ~ ~ ~ coordinates are relative, so each pig appears right where its player stands.
Bedrock also has context modifiers that change other parts of the setup:
– in sets the dimension, as in /execute in nether run say hi. – positioned sets an exact spot. For example, /execute positioned 100 64 -200 run summon minecraft:pig places the pig at that coordinate. – rotated sets the rotation of the runner, such as rotated 90 0. – facing turns the runner to look at a point, such as facing 100 64 -200. – align snaps the position to the block grid, such as align xyz. – anchored picks which point, eyes or feet, is used as the origin, such as anchored eyes.
Each modifier is optional, so you only add the ones your build needs.
Which Target Selector Should You Use?
The six base selectors in Bedrock Edition are @p, @a, @r, @e, @s, and @initiator. Each one picks a group of targets, and you can narrow that group with filters.
- @p picks the nearest player.
- @a picks all players.
- @r picks a random player.
- @e picks every entity, including mobs, items, and players.
- @s picks the entity running the command.
- @initiator picks the player who started the command.
Filters go inside square brackets placed right after the selector. Separate multiple filters with commas. A target is selected only if it matches every filter you wrote, so each filter you add makes the group smaller. For a quick example, /execute as @e[type=minecraft:bat] run say hi makes only bats run the command. Players, cows, and zombies are skipped.
Distance filters work the same way. The filter rm sets the minimum distance and r sets the maximum, both measured in blocks from the execution origin. So @e[rm=3,r=10] selects entities that stand 3 to 10 blocks away. Put an at modifier before it, such as /execute at @p as @e[rm=3,r=10] run say hi, and the ring is drawn around the nearest player.
Here is a tip that trips up many builders. Inside an execute as, @s refers to the entity the command is running as, not the player who typed it. In /execute as @e[type=minecraft:bat] at @s run say hi, each @s is the bat itself, so the bat is the one whose position the next part of the command uses.
The examples here use Bedrock syntax, so check the Microsoft Learn target selector guide and your edition’s rules before you copy them into a Java world.
How Do if and unless Conditions Work in Redstone Builds?

Use if when you want a command to run only when a condition is true, and unless when you want it to run only when that condition is false. Both sit in the setup part of an /execute line, before run.
A simple redstone trigger can start with a block check. In Java Edition, /execute if block 10 65 10 minecraft:redstone_block run say powered sends the word “powered” to chat only while a redstone block sits at 10 65 10. Put that line in a repeat command block and the check runs every tick, so the message appears as soon as you place the block.
Scores work well for counting. Set up a scoreboard objective named counter, then try /execute if score @s counter matches 5.. run function example:open_door. The function runs only when the player’s counter is 5 or higher. The matches 5.. range means “5 or more,” so you do not need a separate check for each value.
The store modifiers save a result instead of checking one. store result saves the number a command returns, while store success saves whether the command worked. For example, /execute store success score @s counter run say hi writes the outcome into the counter score, and a later if score line can read it. You can also store results into an NBT path when you need the data to stay on an entity.
Some condition types are Java-only. The if slots and unless slots conditions, added in Java Edition 26.3 (2026), check whether an inventory holds certain items, which makes them useful for item-based builds. Bedrock Edition does not support every Java condition, so check your edition before you copy a line from a Java example.
Running Commands for Every Player With as @a
Adding as @a turns one command into many. Minecraft runs the rest of the line once for every matching player, and each of those runs is called a fork. So /execute as @a run say hello sends the message once per player, not once in total.
Now try a trigger that teleports only players standing on a gold block. In a flat test world, place a gold block at 0 60 0 and stand on it, so your feet sit at 0 61 0. Then type this line in Bedrock Edition with cheats on:
/execute as @a at @s if block ~ ~-1 ~ minecraft:gold_block run tp @s 0 64 0
Each player is checked from their own position. The ~ ~-1 ~ part looks one block down, so only players whose feet are above the gold block get moved.
You can also run a command from another entity’s position. Summon an armor stand at 20 64 20 and run:
/execute as @a at @e[type=minecraft:armor_stand] run summon minecraft:pig ~ ~ ~
Each player gets a pig dropped at the armor stand’s spot.
Every fork runs on its own, so one player’s teleport does not wait for the others. Ten players standing on the gold block means ten separate teleports in the same moment. Put the line in a repeat command block and each fork can fire on every tick, which adds up quickly. Keep the list of matching players small, or the command will do a lot of work each tick.
How Do You Use Execute in Command Blocks Safely?

To use execute safely in a command block, pick the right block type, keep heavy work off repeating blocks, and check your world settings first. On Bedrock Edition, you need Creative mode before you can edit a command block. Enabling cheats also disables achievements for that world, so test in a separate world if you want to keep your progress. The Microsoft Learn introduction to Bedrock commands covers both rules.
Bedrock command blocks come in three types, and each one fires differently. The Microsoft Learn command block guide describes them in detail, and here is the short version:
- Impulse runs once each time it receives a redstone signal.
- Chain runs after the block before it, and its behavior depends on its condition.
- Repeat runs again on every in-game tick.
A conditional chain block runs only if the previous block succeeded. An unconditional chain block runs regardless of that result. Use conditional chains when a later step should depend on an earlier /execute check passing.
Repeat blocks are where lag usually starts. Bedrock runs 20 ticks per second, so a Repeat block running /execute as @a at @s fires once for every matching player, 20 times each second. A big selector with many entities multiplies that work fast.
Here is the tip we recommend most: put heavy execute chains on an Impulse block triggered by a redstone signal instead of repeating them. Wire a lever or button to the Impulse block, and the chain runs once each time you flip the switch.
Why Does Your Execute Command Fail?
Most failed /execute lines come from a few beginner mistakes, and each has a quick fix. Check these first whenever a command does nothing.
Forgetting run is the simplest one. Without run, Minecraft never reaches the command you wanted to execute. Before: /execute as @a say hello. After: /execute as @a run say hello.
Modifier order matters too. Put at before as, and the position comes from you, the one typing, instead of from each player. Before: /execute at @s as @a run summon minecraft:pig ~ ~ ~. After: /execute as @a at @s run summon minecraft:pig ~ ~ ~.
A selector matches nothing when no target fits every filter. Check these:
– Confirm the entity type and name both exist in your world. – Remove one filter at a time until something matches. – Spell the type exactly, such as type=minecraft:zombie.
Coordinates cause confusion in builds. A plain number like 0 64 0 is a fixed spot in the world, so every pig lands on the same block. Relative coordinates like ~ ~ ~ follow the runner’s position instead, so each pig appears where its own runner stands.
Conditions fail silently, so a false check shows no error. Test the check with a simple say command before you add your real action. For example, /execute if block 10 65 10 minecraft:redstone_block run say condition passed shows you the check works. Once the message appears, swap in your real command.
Typos in IDs are easy to miss. A misspelled block or entity ID will never match the real thing in your world. Before: minecraft:redstone block. After: minecraft:redstone_block.
Build Your First Execute Test Setup
Start with one small test in a flat world, where you can see every block and entity clearly. Stand in an open spot, spawn three cows a few blocks apart, and type /execute as @e[type=minecraft:cow] at @s run say moo. If the message appears three times, each cow ran the command from its own position. That tells you your selector matches what you expect.
Next, add a filter to narrow the group. Replace the selector with @e[type=minecraft:cow,r=5] and stand close to one cow. Only the cows within that range should send the message. If none do, remove the r=5 part and try again. Changing one filter at a time makes it easy to find the piece that is blocking a match.
Once the selector behaves, test your condition before you add a real action. Place a redstone block at 10 65 10 and run /execute if block 10 65 10 minecraft:redstone_block run say powered. Remove the block and run the line again. The message should appear only while the block is there. Then swap the say command for the action you want, such as a summon or a teleport.
When everything works in your test world, move the line into a command block, but start with an Impulse block wired to a lever. That way you see the result on each flip, not 20 times per second. Keep your test world separate from your main save, and check the Java or Bedrock section of our guides for any syntax that differs from what you tested.

