Skip to content

Type to search across every guide and reference page.

CommandsBoth · 26.x

Minecraft /execute Command: as, at, if and run With Examples

/execute runs a command as another entity, from another position, or only if a condition is true. The as, at, positioned, if and run parts, with examples.

By minecraft.bd Editorial Team·Updated

/execute runs another command with a changed context: as a different entity, from a different position, or only if a condition is true. A typical line looks like /execute as @a at @s run summon lightning_bolt, which strikes every player with lightning. It’s the backbone of most command block builds.

How to read it

/execute is a chain of subcommands, read left to right, ending in run and the command you actually want:

/execute <subcommand> <subcommand> ... run <command>

The ones you’ll use most:

Subcommand What it changes
as <targets> Who runs it. @s now means each of those targets.
at <targets> Where it runs: their position, rotation and dimension.
positioned <x y z> Run from a set position.
facing <x y z> Change rotation to face a point.
in <dimension> Run in another dimension.
if / unless Only run when a condition is true (or false).
run <command> The command to run. Always last.

Java has a few more, like store (save a result to a score or data), on and summon. Bedrock has had this same modern syntax since 1.19.50, minus Java-only subcommands like store.

Worked examples

Give every player a speed boost, each one running it on themselves:

/execute as @a run effect give @s speed 30 1

(On Bedrock the inner command is effect @s speed 30 1.)

Turn the block under each player’s feet into glowstone:

/execute as @a at @s run setblock ~ ~-1 ~ glowstone

Summon lightning on every zombie:

/execute at @e[type=zombie] run summon lightning_bolt ~ ~ ~

Run a command only if the player is standing on a gold block:

/execute as @a at @s if block ~ ~-1 ~ gold_block run say I'm on gold

Teleport yourself into the Nether at set coordinates. Java:

/execute in minecraft:the_nether run tp @s 100 70 100

Bedrock:

/execute in nether run tp @s 100 70 100

Detect whether any creeper is within 10 blocks of you:

/execute at @s if entity @e[type=creeper,distance=..10] run say Creeper nearby!

On Bedrock, the selector uses r for radius: @e[type=creeper,r=10].

Common mistakes

  • Using as without at. /execute as @a run setblock ~ ~ ~ stone places blocks at the command’s original position, not at each player. Add at @s.
  • Forgetting run. Every chain ends with run <command> unless it ends with a condition.
  • Mixing selector syntax across editions. Java uses distance=..10; Bedrock uses r=10.
  • Typing a slash after run. It’s run say hi, not run /say hi.
  • Old Bedrock syntax in new worlds. /execute @a ~ ~ ~ ... belongs to worlds made before 1.19.50.

Combine /execute with /fill, /summon and /tp and you can build most minigames without mods. The full command list has the rest, or go back to the commands hub.

Common questions

What is the difference between execute as and execute at?

as changes who runs the command (what @s means). at changes where it runs from (position, rotation and dimension). You usually want both: execute as @a at @s run ...

Does Bedrock use the same /execute syntax as Java?

Mostly yes, since Bedrock 1.19.50. Bedrock supports as, at, positioned, rotated, facing, align, anchored, in, if, unless and run, but not Java-only parts such as store.

What did the old Bedrock execute syntax look like?

It was /execute <target> <position> <command>, for example /execute @a ~ ~ ~ say hi. You'll still see it in old command block builds and tutorials, but new commands should use the modern form.

Sources & verification

Facts on this page are checked against these references and in-game behavior for the stated edition(s). how we verify.

Keep reading