First, create the following folder
📂BP
└📄manifest.json
└📚pack_icon.png
└📂functions
└📄target_escape.mcfunction
Enter your command in target_escape.mcfunction
example: summon ender_crystal
Then enable the addon you created and use the block with target_escape.mcfunction.
And if you perform a certain action, you can execute the target_escape.mcfunction.