Your ability to remain in the U.S. on a student visa (F-1 or M-1) depends on your not only going to school and studying as expected, but obeying the broader rules that apply to any visa holder in the U.S., including that you not commit any of various types of crimes.
It is your responsibility to know what is legal or not. Don't follow the example of your fellow U.S. citizen students, who might take their chances with crimes like driving while under the influence of drugs or alcohol (DUI or DWI), using illegal drugs, handling unlawful firearms, and so on.
Below are some of the consequences you could face upon an arrest, and what to do about the situation.
If you commit a crime in the U.S., you will be subject to all the laws and potential punishments that might apply to a U.S. citizen. You may be charged with a crime, jailed while awaiting the trial (or freed upon bail), tried in criminal court, and ultimately sentenced with a fine, prison time, or other penalty.
Many criminal cases are resolved fairly quickly by the person pleading guilty and receiving a reduced sentence in return. But as a foreign-born person, you need to be extra careful about what you plead guilty to, because the conviction will have long-lasting consequences for your immigration record.
Once someone has been charged with a crime in the U.S., leaving the country becomes impossible until the case has been resolved. That can mean weeks, months, or even years of waiting, with no vacations spent with family in the home country.
Regardless of whether the student is ultimately convicted of a crime, the school might not look kindly on whatever behavior led to the arrest. That could result in the student being suspended or expelled from school, thus creating a cascade effect.
The school will also need to report the student's absence from classes and study to SEVIS, which could result in a termination of the student's right to remain in the United States.
If USCIS catches you in a status violation, it could place you and your spouse and children in removal proceedings. Not every crime will make you deportable, but the list is a long one, including any aggravated felony, any crime of moral turpitude, any drug crime (or a conspiracy or attempt to commit one) except a single offense involving possession for personal use of 30 grams or less of marijuana, any abuse of drugs (even without a court conviction), espionage, firearms offenses, and more. See Grounds of Deportability: When Legal U.S. Residents Can Be Removed for more information.
Once you have been removed from the U.S., you will be barred from return for a number of years, typically ten, unless you are eligible for a waiver. On top of this, even if you avoid deportation, the judge will likely find that your violation caused some of your time in the United States to be "unlawful," which will cause another bar to reentry, as described in Consequences of Unlawful Presence in the U.S.--Three- and Ten-Year Time Bars.
If the U.S. consulate in your home country gets wind of your having been arrested for a DUI, it can revoke your visa from afar. For other violations, it cannot take such action while the person is still in the U.S., but an exception is made for DUIs. (See 9 FAM 403.11- 3(U).) The rationale for this exception is that the person was inadmissible upon entry to the U.S., under § 212(a)(1)(A) of the Immigration and Nationality Act, which describes the health-related grounds of inadmissibility.
Even after your criminal case is resolved, and even if the resolution doesn't make you deportable, it could separately make you inadmissible; in other words ineligible for any future U.S. visa or green card. See Inadmissibility: When the U.S. Can Keep You Out for details.
Better yet, get two lawyers: one who specializes in criminal law and one who specializes in immigration law. Very few attorneys are up to speed on both. You wouldn't want to follow a criminal attorneys' advice to plead guilty to something in order to avoid prison time, only to later discover that you have admitted to a crime that will make you deportable from or inadmissible to the United States.