Open System Settings
Click Lock Screen
Set “Turn display off on battery when inactive” to a longer time or Never
Set “Turn display off on power adapter when inactive” to a longer time or Never
Click Battery
Turn off “Put hard disks to sleep when possible” if available
Click Energy Saver if shown
Disable “Prevent automatic sleeping on power adapter when the display is off” if you want sleep behavior unchanged
Keep the MacBook plugged into power
Use Terminal and run `caffeinate` to prevent sleep temporarily
Use third-party apps like Amphetamine or KeepingYouAwake
Close unnecessary apps and background tasks that may trigger sleep settings
Check for scheduled sleep in System Settings or third-party apps
Restart the MacBook after changing sleep settings
