Objective: to analyze the influence of sociodemographic variables, prison context, religiosity, and symptoms of depression on the presence of suicidal thinking in a population deprived of liberty. Method: a cross-sectional study with a quantitative approach, conducted with 228 participants, based on a sociodemographic questionnaire, on the prison context, and on the presence of suicidal thinking, from the Duke Religiosity Scale and the Depression, Anxiety and Stress Scale (DASS-21). Results: the variables that showed a statistically significant correlation were the following: female gender, not having a partner, working inside the penitentiary, being a primary defendant and using controlled medication, and females are 7.2 times more likely to present suicidal thinking, for each point more in the depression score, increases by 21% in the chances and not having a partner increases the chances of thinking about suicide by three times. Although the scores of religiosity were high, they did not present a statistically significant correlation with the presence of suicidal thinking. Conclusion: the prison context is complex and contains peculiarities that cause the involvement of mental health problems, as well as self-harming thoughts. Considering the relevance of the subject at issue, this work stands out in view of the scarce scientific production on the subject.