The basic rule is that no person or entity, other than (1) another non-profit within the scope of the charitable purpose of a non-profit or (2) someone whose benefit is within the scope of the charitable purpose of a non-profit, may derive economic benefit, in excess of fair market value for goods or services provided to the non-profit. As the IRS explains it:
To be tax-exempt under section 501(c)(3) of the Internal Revenue Code,
an organization must be organized and operated exclusively for exempt
purposes set forth in section 501(c)(3), and none of its earnings may
inure to any private shareholder or individual. In addition, it may
not be an action organization, i.e., it may not attempt to influence
legislation as a substantial part of its activities and it may not
participate in any campaign activity for or against political
Organizations described in section 501(c)(3) are commonly referred to
as charitable organizations. Organizations described in section
501(c)(3), other than testing for public safety organizations, are
eligible to receive tax-deductible contributions in accordance with
Code section 170.
The organization must not be organized or operated for the benefit of
private interests, and no part of a section 501(c)(3) organization's
net earnings may inure to the benefit of any private shareholder or
individual. If the organization engages in an excess benefit
transaction with a person having substantial influence over the
organization, an excise tax may be imposed on the person and any
organization managers agreeing to the transaction.
Section 501(c)(3) organizations are restricted in how much political
and legislative (lobbying) activities they may conduct.
Economic benefit, for this purpose, does not include tax code authorized deductions or credits associated with donations to the non-profit. Instead, the notion is to not enter into deals that are unduly favorable to the party dealing with the non-profit, and to not provide excessive perks and compensation to individuals workin with the non-profit that are more favorable than the prevailing non-profit management market.
Non-profits routinely can and do have directors and officers of for-profit companies that support them on their boards of directors. When acting in that capacity, the directors and officers owe a duty of loyalty to the non-profit, and can't put the interests of other businesses with which they are involved above the interests of the non-profit.
The regulations are more specific, and there are some additional requirements that are imposed, in the case of a 501(c)(3) that is a "private foundation" (which is defined, more or less, as receiving most of its donations from a small number of big donors who aren't non-profits themselves). For example, a private foundation is required to spend a certain amount determined by a formula each year for charitable purposes, rather than reinvesting all investment returns and donations for future use. As the IRS explains:
[T]here are several restrictions and requirements on private
restrictions on self-dealing between private foundations and their substantial contributors and other disqualified persons;
requirements that the foundation annually distribute income for charitable purposes;
limits on their holdings in private businesses;
provisions that investments must not jeopardize the carrying out of exempt purposes; and
provisions to assure that expenditures further exempt purposes.
The IRS provides a detailed description of what constitutes a self-dealing transaction at this link. Loans of money between the non-profit and related parties are particularly perilous.