You can prevent your Mac from automatically sleeping when the lid is closed by enabling Clamshell mode
or by tweaking the energy-saver settings, connecting the battery charger, and plugging in an external monitor.
Alternatively, you can install a third-party app
to keep your Mac from sleeping without plugging in an external monitor.
See more results on Neeva
Summaries from the best pages on the web
The problem is that your Mac will go to sleep when you close the lid if it's not plugged in and connected to an external display.
You could set never go to sleep in the System Preferences. Go to Energy Saver > and select 'Prevent your Mac from automatically sleeping when the display is off'.
How To Use MacBook With Lid Closed, Stop Closed Mac Sleeping - Macworld UK
Apple only provides you with one way to keep your MacBook from sleeping with the lid closed, and that’s to tweak the energy-saver settings , connect the battery charger, and plug in an external monitor.
If you want to keep your MacBook from sleeping without plugging in an external monitor, you need to install a third-party app.
How to Prevent a MacBook From Sleeping When Lid Is Closed
When you close the lid of your MacBook, it goes to sleep. There’s no system setting you can tweak, and no command you can run, to change this. But there is a ...
How to Keep Your MacBook Awake While Closed