Quick answer:
Changing sudo reboot
to sudo shutdown -r +m5
or what ever time delay needed, would prevent the pipeline from failing. It forks the reboot process to the system and lets the Jenkins agent finish this pipeline cleanly.
Longer (preventing potential conflicts answer):
Depending on how the system is configured, it should prevent new logins to the server while the reboot is scheduled.
If the agents are configured to launch via ssh,
and configured to be brought offline if not in use,
Provided the agent times out, Jenkins should be unable to start a new pipeline on that agent until the reboot completes.
From the man page for shutdown (on one of my servers)
If the time argument is used, 5 minutes before the system goes down the
/run/nologin file is created to ensure that further logins shall not be
allowed.