While I generally advise clients to do absolutely everything possible to avoid withdrawing from retirement accounts, if you must to survive you may do so in a Chapter 7 without prejudicing your bankruptcy. This is because you are making this conversion "post petition", that is, after your filing date. The result is in all likelihood the same in a Chapter 13 since this does not reflect a new source of income but rather the liquidation of an asset. Be sure to check, however, whether you must seek court approval to make this sale if you are in a Chapter 13.
You can make early withdrawals from a 401(k) plan; however, depending on your age and the structure of the plan, there can be significant penalties. The two most common withdrawal penalties are tax and forfeiture of matching funds/stock because you are not fully vested. The good news is that there are several specific exemptions that allow you to withdraw funds penalty free. I would recommend that you speak with a qualified accountant or tax attorney for advice on you specific circumstances.
For more information on withdrawals and potential tax penalties, I would refer you to the IRS guidance provided in the following link:
Eric M. Rolinson, Esq.
NOTE: If you find this response helpful, please click on the “thumbs up” button at the bottom.
DISCLAIMER: THE INFORMATION PRESENTED HERE IS GENERAL IN NATURE AND IS NOT INTENDED, NOR SHOULD IT BE CONSTRUED, AS LEGAL ADVICE. THIS POSTING DOES NOT CREATE ANY ATTORNEY-CLIENT RELATIONSHIP BETWEEN US. FOR SPECIFIC ADVICE ABOUT YOUR PARTICULAR SITUATION, CONSULT A QUALIFIED ATTORNEY.