Every exposure requires setting up a selection of tracking or 'guide stars' which the telescope uses to determine its pointing direction. The independent optical system for guiding keeps the guide stars 'locked' into position during the entire exposure. HST can use stars down to +15 magnitude for guiding and there are over 19 million of these across the sky. As for the exposure length, usually the exposures are kept very short compared to the time of a single 90 minute orbit. Frequent exposures are made of the same target field, and these exposures are independently calibrated and then 'co-added' to integrate the exposure to the maximum time permitted by the data you have. This lets the astronomer throw away individual exposures or 'frames' that have become corrupted in one way or another, and only stack-up or add together the optimal exposures to achieve the desired total integration time of hours or days. The HST never observes in directions that allow earthlight, sunlight or moonlight to enter the optical path.