Astronauts do not use a special machine to sleep in space, but they do frequently suffer from the effects of sleep deprivation and circadian rhythm disruption. When they do manage to get some shut eye, it requires that they sleep in a crew cabin, or in other words, a small room about the size of a shower stall. They lie in a sleeping bag strapped securely to the wall. Read more for a video and additional information.
Sleeping as well as crew accommodations both need to be well ventilated; otherwise, astronauts can wake up oxygen-deprived and gasping for air, because a bubble of their own exhaled carbon dioxide had formed around their heads. Plus, brain cells are extremely sensitive to a lack of oxygen and can start dying off less than 5 minutes after their oxygen supply disappears.