Are you seeing any error messages in the Console window when your machine shuts off? If there is a specific error, that could tell us more about what’s going on.
Without knowing more, your laser may be losing connection due to a loose USB connection, a USB port sleeping, static discharge causing the controller to reset, or insufficient power supply leading to a brown out condition.
Check your USB connection, and try a new, shielded USB cable. Route your USB so that it avoids the stepper motors or anything else that could cause electrical interference. Make sure that your machine is properly grounded. Make sure there are no devices on the same circuit as your laser that could be causing a power drop or brown out.
Here are some additional resources to help you troubleshoot these issues: