Using the classic example, "promise your first born child". Let's say I entered into a contract with another party (individual or group) and the contract states that I offer a service or product in exchange for another service or product (money probably). There is a clause in the contract that states if the other part is unable to fulfill his/her/their end of the contract, then the other party must give me their first born child. Will this contract hold up in a court of law in the United States? This is assuming the other party was willing and able to enter into this contract with me.
No, a contract cannot require a breach of law.
Any such contract is invalid, but a clause may limit the extent to which it is invalidated, to only such terms as actually or require a breach of law.
While not precisely on topic (the other three answers, when taken together, are correct), your question reminded me of something I see every time I go to pay for an order with a credit or debit card at my local Safeway grocery store.
Once the charges are totaled up for you purchase, it is sent to a touchscreen with a stylus for you to choose your payment options and sign authorizing the charges with the stylus on the touchscreen.
On the screen that allows you to select your payment option, in addition to credit and debit, there is a touchscreen button that looks like this:
I initially assumed that this was the "pay for your groceries with your first-born child" option, which had apparently become a common payment plan for their customers (Safeway is the most expensive of the several general purpose grocery stores in my area), and began asking myself your question.
Later, I learned this icon represents a payment made via the Women, Infants and Children (WIC) benefits program, with the icon featuring a woman, her infant and her child, which now has an electronic payment option. The inference I made initially still seems reasonable to me in light of the icon, however, perhaps because I have read too many of Rachael Caine's Morganville Vampires books, in which such payment plans are common.
Your title assumes something not in evidence: that there are laws forbidding a person giving a child to another person, who would become their guardian. It is likely that such a contract would be unenforceable as unconscionable, see this as well. Courts dislike ordering specific performance. Name Drop has yet to sue users to enforce the first-born provision of their TOS.
Answering your question, but disregarding your example, the answer is: YES, contracts can supersede the law.
There are two ways:
First, parties to a contract enjoy usually the freedom to contract. They are free to agree on their own terms. The agreement may deviate from the rule the law would impose, if there would be no such agreement. For example, a law may provide for a rule where the buyer under a sales contract bears the risk that the property is destroyed on its way from seller to buyer. The parties to the specific sale contract may agree otherwise. This freedom may not exist where the law is mandatory. Whether a law is mandatory may not be obvious. Where there is a penal provision that establishes criminal liability for any contravention of the civil law, however, this would be a clear case.
Secondly, the freedom to contract often encompasses to choose the law applicable to the contract. For example, the parties - both resident in South Africa - may agree on that a sale contract is governed by French law. Where seller subsequently sues buyer for damages arising under said contract, the court seised would first ask whether this choice was valid. If so, French law applies. Where the case, for example, was brought in the US and the court has jurisdiction, the court would have to apply French law. Regardless whether this would contravene a mandatory US (state) law, c.f. s.186(2) Restatement 2nd Conflict of laws. The foreign law is nonetheless not applied where it would be against a fundamental policy or public order of the law of the forum, here the US (state).