Are there any restrictions for citizens of sanctioned countries to work remotely for US companies?
There is a regulation 31 CFR 560.419 making it
unlawful to hire an Iranian national ordinarily resident in Iran to come to the United States solely or for the principal purpose of engaging in employment on behalf of an entity in Iran or as the employee of a U.S. person, unless authorized pursuant to §560.505
If the work is conducted long-distance, the employee would not be coming to the US. An additional regulation is 31 CFR 560.201, that
Except as otherwise authorized pursuant to this part, and notwithstanding any contract entered into or any license or permit granted prior to May 7, 1995, the importation into the United States of any goods or services of Iranian origin or owned or controlled by the Government of Iran, other than information and informational materials within the meaning of section 203(b)(3) of the International Emergency Economic Powers Act ( 50 U.S.C. 1702(b)(3)), is prohibited.
which could be applicable. 50 USC 1702 says that there is no prohibition against
the importation from any country, or the exportation to any country, whether commercial or otherwise, regardless of format or medium of transmission, of any information or informational materials, including but not limited to, publications, films, posters, phonograph records, photographs, microfilms, microfiche, tapes, compact disks, CD ROMs, artworks, and news wire feeds. The exports exempted from regulation or prohibition by this paragraph do not include those which are otherwise controlled for export under section 4604 of this title, or under section 4605 of this title to the extent that such controls promote the nonproliferation or antiterrorism policies of the United States, or with respect to which acts are prohibited by chapter 37 of title 18
It is not obvious how the US government will interpret "information". Following the rule noscitur a sociis, outsourcing accounting services is not clearly "information" given the instances enumerated in the law.
Then we come to 31 CFR 560.206, whereby
no United States person, wherever located, may engage in any transaction or dealing in or related to:
(1) Goods or services of Iranian origin or owned or controlled by the Government of Iran; or
(2) Goods, technology, or services for exportation, reexportation, sale or supply, directly or indirectly, to Iran or the Government of Iran.
(b) For purposes of paragraph (a) of this section, the term transaction or dealing includes but is not limited to purchasing, selling, transporting, swapping, brokering, approving, financing, facilitating, or guaranteeing.
An Iranian person is subject to Iranian law: I won't try to figure out if there is any Iranian law against such an arrangement, but I assume that it is legal from the Iranian side. In light of 560.206, it may be illegal under US law; however, an Iranian person is not subject to US law. The US company would be.
Before giving up hope, I will point out that 560.206 starts with "Except as otherwise authorized pursuant to this part" (Part 560). There is a sort of contradiction between the prohibition in 560.201 and the one in 560.206, that the former states an exception (about information) to a general prohibition, but that exception is not stated in the later (which is about transactions). The government probably would not interpret the information exception in 506.201 as an "authorization". Instead, specific authorizations are found in Subpart E. The majority of those authorizations pertain to exporting the service of obtaining a non-immigrant visa, but also under 506.509 authorized importation of and payment for certain intellectual property services. However, what is enumerated is services pertaining to copyright and patent registration, and not the creation of IP.
Bear in mind that US law is fluid and will change on Nov 4. The Office of Foreign Assets Control is authorized to grant licenses for transactions with Iran. The company that an Iranian might enter into an agreement with bears primary responsibility for navigating the legal waters, but if a company mishandles the transaction, the Iranian person may end up not being compensated for his work. Normally one would hire an attorney versed in relevant law, and there are firms that specialize in the law of Iran sanctions, but such consultations may be difficult for the ostensive Iranian contractor.