Sleepwalking seems to run in families, so some people may be more genetically at risk. However, many other factors can also play a role. Anxiety or sleep deprivation can lead to sleepwalking, as can certain medications, such as antidepressants and over-the-counter sleeping pills. Untreated physical and mental health conditions, including obstructive sleep apnea, depression, and obsessive-compulsive disorder (OCD), can further increase your risk of sleepwalking.