When angry demonstrators sacked the American embassy in Tripoli in 1979, a worried friend cabled former CIA agent Edwin P. Wilson in the Libyan capital: "Get out of there. It's getting too hot."

"The hell with you," Wilson shot back. "It's just getting interesting."

The retort struck the note of pride, self-confidence and machismo that marked the Wilson style, say some who knew him when he was a spy.

Now that the good days are gone for Wilson, old acquaintances are searching for clues to what went wrong. At 54, the 6-foot 4-inch former agent is stoop-shouldered, his skin sallow from lack of sunshine, his hair fully gray. He appears to have lost weight, thanks, says defense lawyer Patrick M. Wall, to his tough, new life behind bars.

It has been a long fall from grace --from CIA covert operative and naval intelligence officer, to alleged arms and explosives supplier for Libyan ruler Muammar Qaddafi's international terrorists. Wilson was arrested last June in New York after committing a fundamental error of espionage tradecraft--he trusted the wrong man.

Once known to colleagues as a loyal American agent eager to infiltrate hostile governments, Wilson today is in deep trouble with the country he professed to love. Twice convicted in recent months, he faces 32 years in prison for his Libyan dealings. He won acquittal here March 4 on two murder conspiracy counts--a partial settling of scores with federal prosecutors, whom he has denounced bitterly. But the victory may be short-lived.

Wilson is scheduled to be tried again soon in New York on charges he conspired--with his son Erik, 22--to have two assistant U.S. attorneys and seven other people assassinated.

It is that allegation that most troubles friends who say they believe, or want to believe, Wilson's claim that a secret motive involving national security lay behind his activities in North Africa.

"I loved the guy," says Howard E. Wickham, president of a Washington graphics firm and the best man at Wilson's wedding in the late 1950s. "But if some of these recent revelations are true--Jesus . . ."

Unlike the old days, when he was "jovial" and a "fun person," according to a friend, Wilson the prisoner has kept silent. He has yet to take the witness stand, except briefly in an Alexandria hearing last month at which he refused to testify. He sits at the defense table, sometimes whispering to his lawyers, frequently taking notes or doodling, and arching thick, black eyebrows that appear -- perhaps unfortunately -- sinister.

Wickham says he attended part of Wilson's trial last fall in Alexandria as a show of support for his old friend. "Hi, buddy," said Wilson, John Wayne-style, as he was led down a corridor in handcuffs.

Wilson has spoken out in public only once in the 10 months since his arrest--an angry, contemptuous, six-page statement released by his lawyer the day after Wilson's conviction on explosives-smuggling charges in Houston.

"I have been silent much too long," the broadside began. It then lashed out at the Justice Department and the CIA for what Wilson called leaks to the press "orchestrated with perfect timing" to influence the judge and the public against him. "It is interesting to note that one of the functions of the CIA is to influence and sway public opinion throughout the world. They are experts in this field," Wilson wrote.

" . . . I have been cut off from people and held in solitary, treated like an animal . . . ," he added.

Prosecutors acknowledge Wilson lost his visitor and telephone privileges and was placed in isolation after he was taped allegedly trying to arrange the murders of Assistant U.S. Attorneys E. Lawrence Barcella Jr. and Carol Bruce from his New York jail cell last fall.

"He's a mover, a guy who sleeps four or five hours a night, a guy who doesn't sit around for a month or two waiting to see what's going to happen," says one federal agent familiar with the government's five-year investigation of Wilson's alleged dealings abroad.

It was typical of Wilson, the same agent says, to become so embroiled in his business deals and maneuverings that he would throw away caution while talking on an open telephone line.

"He'd start out cautious on a phone line he suspected was tapped by the Libyans ," says the agent, describing the way Wilson would issue orders to employes many of whom had code names from his villa in Tripoli. "Then he'd wind up saying, 'I want this stuff delivered right now,' and pounding the desk."

The image of Wilson as a wheeler-dealer -- "consumed by greed," as one prosecutor put it -- was bolstered by a former employe, the late Kevin P. Mulcahy, in recently released testimony before a Washington federal grand jury investigating Wilson and his onetime business partner, Francis E. Terpil.

"Frank is more -- he's an excitement, adventure-oriented guy," said Mulcahy. "Ed is a very cold, down-to-earth, bread and butter -- he's a money man. He lives, breathes and he dies a dollar. Frank can't ask for a buck; Ed can. Ed does it regularly and he's good at it.

"He was hard-nosed, always on his toes, and not afraid to talk to anybody, from a longshoreman to the minister of education of France. He worked hard," says Wickham, who met Wilson when both men were young Marine officers in the early 1950s at Quantico.

Wilson was raised on a farm in Nampa, Idaho, near Boise, according to Wickham and court documents filed in the Wilson case. A defense lawyer has said the family was poor. Wilson was 14 when his father died and he became the family's main provider.

"He worked for the Seafarers Union for a year to raise money for college," says Wickham. "He prospected. He drove a cattle truck. For a while, he and his two brothers had a combine and worked their way through the West. Then in September he'd go back to college."

Stationed in Korea, Wilson was recruited out of the Marines into the CIA in 1955 at the height of the cold war. One of his earliest assignments, according to court papers and a former CIA official, was as a security officer in the U-2 spy plane project. He was married in the late '50s in New Jersey, with Wickham at his side.

Soon afterward he was posted to Brussels where, Wickham says, Wilson was involved as a covert operative with the international trade union movement in Europe. A few years later, he surfaced in both North and South America. A former friend, Ernest Keiser--who later would play a critical role in Wilson's arrest -- says he met Wilson in either Argentina or Chile in about 1960.

"We had a few drinks," says Keiser, who describes himself as a former CIA contract agent. He depicts Wilson then as a "tremendous agent" and a "good man" who had grown up "very, very poor." Keiser next saw Wilson, he says, in Miami, around the time of the CIA's Bay of Pigs invasion in 1961.

By the mid-1960s, Wilson was in Washington, working as a lobbyist for his old union, the Seafarers International, apparently while still on the CIA payroll. The job drew him to Capitol Hill, where he cultivated his contacts. And one contact may have cultivated Wilson in return.

According to a source, Wilson confided his role as a spy to a Senate aide with whom he had become friendly. The aide, says the source, fell under FBI scutiny for alleged ties to the KGB, the Soviet espionage organization. The CIA later considered Wilson's cover as an agent blown.

Although he left the agency in 1971, Wilson signed on almost immediately with a then-secret naval intelligence group, Task Force 157. A source familiar with the organization says Wilson was hired without the usual background security checks that might have raised questions about his Hill dealings.

Wilson subsequently was fired in 1976 by Admiral Bobby Inman, then the head of naval intelligence, who has said he was troubled by business activities Wilson was engaged in while on the government payroll. The same year, Wilson allegedly started his relationship with Qaddafi.

The mixing of business and government service was nothing new. Wickham says he was contacted by Wilson sometime in the mid-1960s about setting up a CIA "proprietary," a legitimate business to serve as a cover for spy activities. The two men established Maritime Consulting Associates, with offices in the District.

"They the CIA briefed my wife and me about the business," Wickham recalls. "Not so much what to say, as what would happen if we ever talked." Wickham says the consulting firm gave Wilson a valid cover for his agency travels. "I told Ed I didn't want to know anything about the covert side, and now I'm glad I did," he says.

Through it all, according to Wickham and others, Wilson was always the hard-charging, hard-working patriot/businessman. "He never had a nickel in his pocket," says Wickham. "Every time he got ahead, he invested it. It's how he bought the farm in Upperville"--a 2,300-acre estate in Virginia's hunt country.

Years later, Ernest Keiser says he found Wilson, then under indictment and living as a fugitive in Tripoli, was still the super-salesman. Keiser, secretly working with U.S. authorities, visited Libya in 1981 to talk to Wilson about coming home to surrender.

During their talks at Wilson's "beautiful villa," Keiser says, the former spy was bursting with plans. Using his Mideast contacts, Wilson said, they could effect the rescue of Gen. James Dozier, then held by the terrorist Red Brigades in Italy. They could bring about peace with the Palestine Liberation Organization. With Wilson as an unofficial back channel, they could even restore relations between Libya and the United States.

Keiser says that after he learned more about the terrorist training camp Wilson was running for the Libyans, "I knew what I had to do" --trick Wilson into leaving Libya to be arrested by U.S. agents. But as he sat in Tripoli, listening to the grand plans, Wilson's rhetoric gave him pause.

"I thought maybe we can pull off something great here," says Keiser. "I swear to God, I really thought so."