Could running laborious code for many hours damage my mac?
Well, make sure your computer is on a solid surface with space around it to permit a good flow of air.

If you can have it in a cool room instead of a warm room would help.

A computer getting warm when working hard is not a problem, but if it gets too hot is - so you should check the temperatures if possible - a fan control program is a possibility.

One other possibility may be to pause the running program and allow the computer to cool down but this may not be possible...