An important doctrine of contract law is privity of contract, to the effect that only parties to an agreement have legal obligations and benefits from the contract. However, there can be third-party beneficiaries, where a third person may gain a benefit, and may rely on that benefit. For example, A agrees to work for B, who will pay C (perhaps because A owes money to C); C can then sue B for non-payment. In order for this right to materialize, C's rights must have "vested", for example C must have relied on the agreement to his detriment, or he has agreed to this with at least one party, or there can be some clause in the contract whereby his rights vest.
That said, in order for a person to by obligated by a contract, they must be a party to the contract – they must have agreed to take on an obligation. (A person can also be obligated, without assent, if there is a specific law – e.g. you are obligated to pay the government your taxes, even if yo didn't agree to it).