How do I use Minecraft command blocks to make a radius that the player cannot leave? [closed]

You have a few ways to solve this, just decide which one fits you best.

This is the most obvious solution to your problem

Put the commands into a repeating command block for them to work propperly

To prevent players at spawn to move at all:

execute positioned <spawn coordinates> run tp @a[distance=..1] ~ ~ ~

To give them a little space to move:

execute positioned <spawn coordinates> run tp @a[distance=3..5] ~ ~ ~

To give them an area to explore, but still restricted:

execute positioned <spawn coordinates> run tp @a[distance=50..52] ~ ~ ~

You can just change the distance parameter to fit your needs.

You could also do a tag based solution

To give them a little space to move:

execute positioned <spawn coordinates> run tp @a[distance=3..,tag=!canLeaveSpawn] ~ ~ ~

Use this command to allow a player to leave spawn if you set it up with this solution:

/tag <player> add canLeaveSpawn

Or a solution based on barrier blocks

Just set up a wall of barrier blocks, you can give yourself a barrier block with this command, no command block is required for this:

/give @s minecraft:barrier

Edit:

It may be possible to escape if you can go really fast, but this is about as close as you can get to an invisible wall without using barrier blocks:

/execute positioned <spawn coordinates> as @a[distance=3..6] facing entity @s feet run tp @s ^ ^ ^3

If players can escape, increase the 6 in this command, if you want a bigger area, increase the 3 in the target selector and at the end (both should get the same value)