Cuban assistance to the Sandinista National Liberation Front

The government of Cuba assisted Nicaragua's Sandinista National Liberation Front (FSLN) both before and after they took power in 1979. This was prompted by their shared Marxist ideologies and resistance to the policies of the United States government.
Pre-revolution.
Beginning in 1967, the Cuban Dirección de Inteligencia (DGI) had begun to establish ties with various Nicaraguan revolutionary organizations. By 1970 the DGI had managed to train hundreds of Sandinista guerrilla leaders and had a strong influence over the organization. In 1969 the DGI had financed and organized an operation to free the jailed Sandinista leader Carlos Fonseca from his prison in Costa Rica. Fonseca was re-captured shortly after the jail break, but after a plane carrying executives from the United Fruit Company was hijacked by the FSLN, he was again freed and allowed to travel to Cuba. 
DGI chief Manuel "Redbeard" Piñeiro commented that "of all the countries in Latin America, the most active work being carried out by us is in Nicaragua." After the successful ouster of the right-wing Somoza dictatorship, DGI involvement in the new Sandinista government expanded rapidly. An early indication of the central role that the DGI would play in the Cuban-Nicaraguan relationship was a meeting in Havana on July 27, 1979, at which diplomatic ties between the two countries were re-established after more than 25 years. Julián López Díaz, a prominent DGI agent, was named Cuban Ambassador to Nicaragua. Cuban military and DGI advisors, initially brought in during the Sandinista insurgency, would swell to over 2,500 and operated with all levels of the new Nicaraguan government.
While the Cubans would like to have helped more in the development of Nicaragua towards socialism, it was difficult to counter the United States' power and influence in the rest of Central America and the assistance they gave to the Contras. Following the more overt US invasion of Grenada, countries previously looking for support from Cuba saw that the United States government was likely to take violent action to punish this.
Post-revolution.
The early years of the Nicaraguan Revolution were strongly influenced by Cuba. The Sandinista leaders acknowledged that the FSLN owed a great debt to the communist island. The relationship was made possible because of Cuba's commitment to the strategy of revolutionary guerrilla warfare. Once the Sandinistas assumed power, Cuba gave Nicaragua military advice, as well as aid in education, health care, vocational training and industry building for the impoverished Nicaraguan economy. In return, Nicaragua provided Cuba with grains and other foodstuffs. Once the Sandinistas assumed power, Cuba began sending aid, and it became an essential component of Nicaraguan development strategy. Cuban aid was more beneficial than most countries' because it came in the form of grants and unconditional loans. (Roberto Perez, 1987) During the Somoza period, Nicaragua had been nearly 90% dependent on the US for assistance. In 1980, Cuban-Nicaraguan aid relations became formalized with the formation of the Mixed Commission for Scientific, Economic and Technical Cooperation. This commission is represented on the Cuban side by the State of Committee for Economic Cooperation and on the Nicaraguan side by the Ministry of Economic Cooperation. New aid agreements were negotiated every year within the framework of the commission. In this context the commission provides a vehicle for Nicaragua to present its various needs and for Cuba to evaluate which ones they can fulfill. From 1979 to 1987, the commission oversaw approximately 300 million dollars (US) in aid to Nicaragua, which according to Prevost does not include military aid or the cost of schooling Nicaraguans in Cuba.