DMX now on house arrest after failing 4 drug exams.

Apparently DMX pissed off the judge in his criminal case something fierce, after showing up more than 30 minutes late to his bail bond hearing ... but he still dodged the jail bullet.

The rapper and his attorney, Murray Richman, showed up to court Friday morning in NYC and the judge gave him an earful ... notably, X failed 4 drug tests for pot and cocaine.  

The rapper is out on bail in his tax evasion case, and one of the conditions is no drugs. X violated another condition -- not leaving the state without court permission --- by flying to St. Louis to handle some family matters.

The judge could easily have thrown the rapper in jail, but showed him mercy by putting him on house arrest. To make sure he doesn't stray, X has to wear an ankle bracelet. The judge was pretty clear, telling X he couldn't even go out to mow his own lawn.

TMZ broke the story ... DMX faces 14 counts of evading more than $1 million in federal taxes.