If a company is already in bankruptcy, but wants to engage my services or buy my product, what should I be aware of? Is that just a completely dumb idea? What can I do to protect myself?
Chapter 11 or 7? Companies in bankruptcy can enter into enforceable contracts -- they generally need to be approved by the bankruptcy judge or be entered into "in the ordinary course of business." If it's a Chapter 7 bankruptcy, then the company is supposed to be closing up shop in an orderly manner.
Talk with an attorney -- the right answer depends on where they are in the bankruptcy process, the nature of your contract, and on how your contract was approved.
You need legal advice from a lawyer. Not only do you run the risk of not getting paid, but the bankruptcy courts can also take back money you do get paid.
This is easy - get paid before you perform the services or deliver the product. Explain to them you understand they are under bankruptcy protection and as a small business owner you need to make sure you receive prompt and consistent payment.
If that doesn't work for them then save yourself the potential hassle - no deal.