In trying to avoid sleep paralysis we should know how this condition is brought about and how it manifests it self. In the following paragraphs I will give an in depth and yet simple to understand overview of the illness and what you can do to avoid it. Sleep paralysis has been acknowledged as a medical condition that is classified under sleeping disorders. It always occurs during the periods when people are about fall asleep or just coming out of sleep.
When people are having dreams; the brain automatically paralyzes the body as a protective measure. This is so that the action that is occurring in a person's dream is not translated into actual actions. The process of the body coming out of sleep into a state of full consciousness is a gradual and not immediate process.
If however it happens that during these episodes that we experience dreams we attain consciousness whilst the body is still asleep. You become trapped between the two states of consciousness where the dream you are having is a partial reality for you. You try and move but because the body understands that it's in a dream you are paralyzed. I know how terrifying that can be and would want to avoid sleep paralysis as much as you.
So what can you do to prevent it? Firstly you need to maintain a constant sleep pattern. Try and always go to sleep and wake up at the same time everyday. Inconsistent sleep patterns are disruptive to normal sleep.
If you want to avoid sleep paralysis then your room should be free of disturbances that will affect your brain in your state of sleep. Avoid light and sound which tend to quickly bring the brain out of sleep. This is an extensive subject that has been well researched; more detailed and comprehensive answers are available.