The amount that counts as a withdrawal will always be subject to regular income tax. There's no way around that, the contributions were tax-free, so withdrawals are always taxed.
There is an additional 10% penalty if you are under age 59-1/2. There are also several exceptions, they are listed here (note they are different for 401ks and IRAs). https://www.irs.gov/retirement-plans/plan-participant-employee/retirement-topics-exceptions-to-tax-o...
Notably:
- If you left service with the company and are age 55 or older
- If you used the money to pay for medical insurance while unemployed
- If you had medical expenses that were more than 7.5% of your adjusted gross income
- Up to $1000 for an "emergency personal expense." (New in 2024)
Being unemployed is not by itself, an exception to the penalty. But you can claim $1000 as an emergency personal expense and just pay the penalty on the other $900. You might also have medical insurance or medical expenses that would count.