U.S. Immigration and Customs Enforcement arrest someone during a targeted enforcement operation in early 2017. (Charles Reed/AP)

The inspector general for the Department of Homeland Security has criticized several immigration detention facilities for having spoiled and moldy food and inadequate medical care, and for inappropriate treatment of detainees, such as locking down a detainee for sharing coffee and interfering with Muslims’ prayer times.

Acting Inspector General John V. Kelly, who took over Dec. 1, said the watchdog agency identified problems at four detention centers during recent, unannounced visits to five facilities. The Dec. 11 report , released Thursday, said the flaws “undermine the protection of detainees’ rights, their humane treatment, and the provision of a safe and healthy environment.”

“Staff did not always treat detainees respectfully and professionally, and some facilities may have misused segregation,” the report found, adding that observers found “potentially unsafe and unhealthy detention conditions.”

Immigration and Customs Enforcement jails tens of thousands of immigrants for civil immigration violations, holding them until they are deported or released in the United States. The jails are not supposed to be punitive, according to the report.

ICE concurred with the inspector general’s findings and said it is taking action to fix the problems, some of which have already been addressed.

“Based on multi-layered, rigorous inspections and oversight programs, ICE is confident in conditions and high standards of care at its detention facilities,” the agency said in a statement. “To ensure the safety and well-being of those in our custody, we work regularly with contracted consultants and a variety of external stakeholders to review and improve detention conditions at ICE facilities.”

The Office of Inspector General said it launched the surprise inspections after receiving complaints from immigrant advocacy groups and on its hotline about treatment of detainees. The inspectors also interviewed staff members and detainees and examined records.

Advocates for immigrants said the report reaffirmed their long-standing calls for the detention facilities to be closed. Advocates have complained about reports of physical and sexual assaults, deaths in detention and other concerns for years under past presidents — and say their worries are increasing under President Trump.

Trump has pledged to dramatically increase deportations and is seeking congressional approval for more than 51,000 detention beds this fiscal year, up from about 30,000 under President Barack Obama.

Trump’s pick for the permanent director of ICE, Thomas D. Homan, previously ran the ICE detention system.

“The realities documented by the OIG inspectors, and many more, are endemic to the entire detention system,” Mary Small, policy director at Detention Watch Network, a nonprofit group that monitors immigration detention, said in a statement. “ICE has proven time and time again to be incapable of meeting basic standards for humane treatment.”

In a statement, Azadeh Shahshahani, legal and advocacy director of Project South, in Atlanta, cited the death in May of Jean ­Jimenez-Joseph.­ The 27-year-old Panamanian national was held in solitary confinement for 19 days at the Stewart Detention Center in rural Georgia, according to Project South.

Shahshahani said his death “should have served as a final wake-up call and resulted in the immediate closure of the facility.”

The Inspector General’s office did not provide the dates of the inspections and did not respond to multiple requests for comment.

Officials praised one facility, in Laredo, Tex., for its treatment of immigrants and said the severity of problems at the other detention centers varied.

At all four facilities, the Homeland Security watchdog said, kitchens had “moldy produce” and thawing meat in packages that failed to indicate an expiration date. Multiple detainees said they faced long waits for medical care, including those with painful conditions such as infected teeth and a knee injury. Two detainees, one at the Hudson County Jail in New Jersey and another at the Santa Ana City Jail in Santa Ana, Calif., waited months for eyeglasses.

In some facilities, immigrants with criminal records were housed with noncriminals, the report said. Jailers sometimes did not use interpreters to communicate with detainees, and some staff members failed to take detainees’ grievances.

In the Stewart center, staff members sometimes interrupted or delayed Muslim prayers. In Santa Ana, officers strip-searched all detainees, a violation of existing policy, and one guard launched a “hostile and prolonged rant” at immigrants and threatened to lock them in their cells.

ICE stopped housing detainees at the Santa Ana facility in May, a spokeswoman said.

Detainees are supposed to be able to make phone calls, including to the Office of the Inspector General to lodge complaints. But at Stewart, a call to the agency’s hotline resulted in a message that said that number was restricted. And at the Otero County Processing Center in New Mexico, inspectors found several broken telephones.

Detainees also complained about mold and peeling paint at the Otero and Stewart centers. At Stewart, some bathrooms lacked either hot or cold water.

Several detainees at the Hudson jail and Stewart also complained that basic supplies, such as toilet paper, soap and toothpaste, were not provided promptly or at all.

The Inspector General issued a separate report in March, after visiting the Theo Lacy detention center in California in November 2016, which detailed similar findings about food handling and other issues it said required immediate attention.