Lindsay Lohan tested positive for cocaine last week and that is why she failed her drug test ... sources tell TMZ.

As we first reported, Lindsay failed the court-mandated drug test -- and according to the terms of her probation, she will go back to jail for 30 days as a result.

Sources close to Lindsay say she's been telling friends she's "getting her life together." However, we're also told, she's surrounded herself with some "bad influences."