As a matter of terminology, "asylum" implies that the applicant is already in the country where refugee status is sought. Those who arrange refugee status before arriving in the country are typically called "refugees."
This is why the web page for form I-589, Application for Asylum and for Withholding of Removal, says
You may file for asylum if you are physically in the United States and you are not a United States citizen.
In other words, the only legal difference between an asylum seeker and a refugee is the location. By the definition of "asylum," it is not possible to apply for asylum in the US unless the applicant is in the US.
The statutory provisions concerning asylum are found at 8 USC 1158, which says essentially that to qualify for asylum an alien must be physically present in the US and meet the definition of a refugee. The first requirement is at paragraph (a)(1):
(a) Authority to apply for asylum
(1) In general
Any alien who is physically present in the United States or who arrives in the United States (whether or not at a designated port of arrival and including an alien who is brought to the United States after having been interdicted in international or United States waters), irrespective of such alien’s status, may apply for asylum in accordance with this section or, where applicable, section 1225(b) of this title.
The second requirement is at subparagraph (b)(1)(A):
(b) Conditions for granting asylum
(1) In general
The Secretary of Homeland Security or the Attorney General may grant asylum to an alien who has applied for asylum in accordance with the requirements and procedures established by the Secretary of Homeland Security or the Attorney General under this section if the Secretary of Homeland Security or the Attorney General determines that such alien is a refugee within the meaning of section 1101(a)(42)(A) of this title.
There is certainly a process for coming to the US as a refugee, but, as noted in the other answer, it is often impractical. As a matter of law, however, a refugee is a person who is outside the country of nationality, so even applying for refugee status requires being in a country other than one's own.
US law does allow the president to extend the definition of refugees to people in their country of nationality under "special circumstances" and "after appropriate consultation" (see 8 USC 1101(a)(42)). The term "appropriate consultation" is defined at 8 USC 1157(e):
[T]he term “appropriate consultation” means, with respect to the admission of refugees and allocation of refugee admissions, discussions in person by designated Cabinet-level representatives of the President with members of the Committees on the Judiciary of the Senate and of the House of Representatives to review the refugee situation or emergency refugee situation, to project the extent of possible participation of the United States therein, to discuss the reasons for believing that the proposed admission of refugees is justified by humanitarian concerns or grave humanitarian concerns or is otherwise in the national interest, and to provide such members with the following information:
(1) A description of the nature of the refugee situation.
(2) A description of the number and allocation of the refugees to be admitted and an analysis of conditions within the countries from which they came.
(3) A description of the proposed plans for their movement and resettlement and the estimated cost of their movement and resettlement.
(4) An analysis of the anticipated social, economic, and demographic impact of their admission to the United States.
(5) A description of the extent to which other countries will admit and assist in the resettlement of such refugees.
(6) An analysis of the impact of the participation of the United States in the resettlement of such refugees on the foreign policy interests of the United States.
(7) Such additional information as may be appropriate or requested by such members.
To the extent possible, information described in this subsection shall be provided at least two weeks in advance of discussions in person by designated representatives of the President with such members.
So, it would be possible for the president to allow home-country applications for refugee status after jumping through some bureaucratic hoops.
Normally, applications for refuge are handled by the United Nations High Commissioner for Refugees (UNHCR). From the State Department's page on the U.S. Refugee Admissions Program:
Application and Case Processing
When UNHCR — or, occasionally, a U.S. Embassy or a specially trained nongovernmental organization — refers a refugee applicant to the United States for resettlement, the case is first received and processed by a Resettlement Support Center (RSC). The U.S. Department of State’s Bureau of Population, Refugees and Migration (PRM) funds and manages nine RSCs around the world, operated by international and nongovernmental organizations and one U.S. interests section. Under PRM’s guidance, the RSCs prepare eligible refugee applications for U.S. resettlement consideration.
Some refugees can start the application process with the RSC without a referral from UNHCR or other entity. This includes close relatives of asylees and refugees already in the United States and refugees who belong to specific groups set forth in statute or identified by the Department of State as being eligible for direct access to the program.
It's therefore not generally possible to apply for refugee status without first making contact with UNHCR, which may also be impractical.