It will depend on your contract and perhaps where you are in the timeline of that contract.
If you are in the option period, you may be able to back out for very little money.
If you are past the option period stage, backing out could potentially cost you the earnest money, or a lawsuit. If you were paying cash for the house, the judge could potentially force you to close and pay the seller's attorney's fees. If you were using a loan this might be more difficult, but could depend on where you were in the loan process.
Another idea is to offer the seller a breakup fee, even if it is not called for in the contract.
Best to consult your realtor at this point, their broker, and/or an attorney to help you through your decision.
You need review the executed contract with your buyers agent who discuss performance of buyer and seller. The sales contract governs what you can and cant do and "the what if's" you dont close.
More than likely you loss of earnest, option, inspection, appraisal you have paid for.
NOW if you are during the option period of contract you might be able to "back out of contract" with no penalty charges.
NO MATTER what both parties need amend sales offer and present to title company. Sooner you accomplish this better off you are IF you want cancel the executed agreement.
~ National Featured Realtor and Consultant, Lecturer regarding Credit Repair, Mortgage Loan Officer
Your buyer's agent should be able to answer your questions regarding your particular situation.