You can't summon an entity to an unloaded chunk; trying to do so will give you the "Cannot summon the object out of the world" error.
What you can do is summon the entity to a loaded chunk, say a world spawn chunk, and then teleport it to the desired location. You could also change the world spawn location, but this is generally inadvisable, especially for the purposes of a prank, and may still not load until a player moves into them. If you do this for a mob, you'll probably want to give it a custom name so that it doesn't despawn immediately, either in the world spawn chunks or the desired location.
Note that somebody still needs to be online and in the overworld for this to work. If that isn't the case, you'll get the same error again.
You can get a /setblock
command with F3+I.
To do so, you place a chest at 9 2 8
(This works for any block at any coordinates).
Then you fill the chest with the items that you want inside of it:
You can get gray dye like the one from the image with this command:
/give @s minecraft:gray_dye{Enchantments:[{id:"minecraft:fortune",lvl:3s}],display:{Name:'{"text":"5 Point PolyCoin"}',Lore:['{"text":"An Official PolyCoin"}']}}
When you are done, you look at it and press F3+I, there should be a message in chat:
You can now paste your command into a command block, or a text editor by using Ctrl+V (in windows):
/setblock 9 2 8 minecraft:chest[facing=north,type=single,waterlogged=false]{Items:[{Slot:13b,id:"minecraft:gray_dye",Count:1b,tag:{Enchantments:[{lvl:3s,id:"minecraft:fortune"}],display:{Lore:['{"text":"An Official PolyCoin"}'],Name:'{"text":"5 Point PolyCoin"}'}}}]}
You can edit the command, to make it a little shorter, by removing tags that you don't need, if you care about that (This may be more useful with different blocks):
/setblock 9 2 8 minecraft:chest{Items:[{Slot:13b,id:"minecraft:gray_dye",Count:1b,tag:{Enchantments:[{lvl:3s,id:"minecraft:fortune"}],display:{Lore:['{"text":"An Official PolyCoin"}'],Name:'{"text":"5 Point PolyCoin"}'}}}]}
Once you are done you can break the block that you made and use the command to set your custom block at that position. (This works for entities, too, simply look at the entity to get a /summon
command with F3+I)
Best Answer
As long as the chest/chunk is loaded you can use execute in.
In your case it would be something like this:
For example: