Food can take up to a month to pass through a sloth's digestive system. This is a long time, and leaves don't supply much energy. So sloths live in ways that use up as little energy as possible. Moving little and slowly is one way to save energy. They also burn their food at a very slow rate.
Sloths use their surrounding to adjust their body temperatures.
Because of this, a sloth that needs to warm up after a chilly night must climb to a patch of sunlight in the upper canopy. This warms it up, but also puts it in danger. Out in the open, a sloth has no protection. If a hungry eagle spots it, it cannot run. The rest of the time though, down in its usual spots among the leaves, the sloth is pretty safe.