There is an input of work in the carnot refrigerator.
The second law of thermodynamics states that heat does not flow from a cold reservoir to a hot reservoir spontaneously. However, heat may flow from a cold reservoir to a hot reservoir with the input of work.