I think SWOT is on the right track. It is time to get tough. Maybe it is time to change how you think about him. You seem to be stuck making excuses for him, blaming his friends, saying he didn't do that much. He was selling drugs.
You are not doing him ANY favors by thinking of him as your innocent little boy who is being tarred by the same brush as those bad boys who lived in that house. You are not to blame for this. He had choices. He had LOTS of choices. He could have lived by your house rules and had a place to live. There are shelters he could have gone to if he was willing to follow their rules. He could have worked hard at a job and used his money for that. LOTS of people are forced out of foster care at age 18 or out of their parents at age 18 or even younger and they find ways of working one or even 2 or 3 jobs and paying rent and bills and doing it all legally. I know, I have seen it done. It isn't easy, but it happens every single day. Lots of kids follow their parents rules and live at home and work and do what they need to do. Those that don't, CHOOSE to have other consequences.
Your son has CHOSEN to be in jail, and he has CHOSEN prison. I am sorry. I know that it is harsh to say that. He knew the people he was living with. He knew what they were doing was illegal. I don't care what kind of stupid gangster wannabe idiots they were, they knew they were not going to get away with it forever. They knew that the only future in that life was prison. It is a simple fact. You either have to get clean and out of it, or you end up in prison. I know that he may deny this for a long time to come, but it is reality.
Please work on codependence. It really will be a HUGE help to you. You need to move on with your life and be happy. You did NOT choose this. Not one single part of this is your fault. You did every single thing that you could to keep this from happening, but you could not make the choice for him. In addition to Boundaries by Cloud and Townsend, I urge you to read Codependent No More by Beattie. You need to let him worry about him and focus your energies on making your own life as good as it can be. You cannot change his life. Only he can do that. the more you try to change his life, the more frustrated and upset you will be and he will be.