Connect your Surface to its charger.
Make sure your Wi-Fi connection is stable.
Hold down the power button for about 20 seconds to force a shutdown.
Wait 10 seconds, then turn it on again.
See whether Windows resumes the initial setup or returns to the same error.
Try a different Wi-Fi network or a phone hotspot, because some home routers, VPNs, and school or work networks block parts of setup.
If it's stuck mid-way, restart and choose the Reset or Start over option if it appears. On a new device you lose nothing.
Windows 11 may require internet. If you reach the network screen, press Shift + F10 to open a command prompt, type OOBE\BYPASSNRO, and press Enter. The device restarts and shows an "I don't have internet" option, which lets you finish setup with a local account and sign in later.
If every restart fails, download the recovery image for your model from Microsoft's Surface recovery site on another PC, copy it to a USB drive, and boot from it by holding Volume Down while powering on. This reinstalls Windows fresh.