The order was issued Monday by a judge who required both parents to refrain from drinking and using drugs around their two young children and 12 hours before either cares for them. Only Spears was ordered to submit to testing.
"Based on the evidence presented, the court finds that there is a habitual, frequent and continuous use of controlled substances and alcohol" by Spears, Superior Court Judge Scott M. Gordon said in court documents.
Messages left with attorneys for Spears and Federline were not immediately returned.
The judge also said Spears must meet for eight hours a week with a "parenting coach" who will observe and report back to the court about her parenting skills.
Both parents are prohibited from "making derogatory remarks" about each other in their children's presence, and from "using corporal punishment" to discipline them. Each must complete the court's "Parenting Without Conflict" class.