MacBook restarts when idle
Answer: https://support.apple.com/guide/mac-help/set-your-mac-to-log-out-when-not-in-use-mchlp2443/mac

On your Mac, choose Apple menu  &gt; System Preferences, click Security &amp; Privacy, then click General.
Click the lock icon  to unlock it, then enter an administrator name and password.
Click Advanced. Select “Log out after... minutes of inactivity.” Set the amount of time before the user is automatically logged out.

@lhf Thanks!