Bankruptcy is the government’s way of helping people to get out of debt and back on their feet. The purpose of Chapter 7 filing is to obtain a discharge of all your existing debts. When you file for bankruptcy most of your assets become part of the "Bankruptcy Estate," and the trustee can sell part or all your assets and pay your creditors.
There are certain assets that cannot be part of the "Bankruptcy Estate" and therefore cannot be touched. Most retirement accounts are either exempt or not part of the "Bankruptcy Estate" and 401(k) is one of them. The major reason for this is if 401(k) retirement savings were made part of the "Bankruptcy Estate" the filers would drain their retirement funds and might have to be supported by government later in their retirement years.
Although a 401(k) is not part of the "Bankruptcy Estate," if you have taken any loans out of your 401(k), you are responsible for paying all of the money back into your 401(k). Bankruptcy does not release you of this loan.