Thermal machines beyond the weak coupling regime