Seven candidates to become Costa Rica's next president went behind bars to hold an unusual debate in a prison where they answered inmates' questions about their election platforms.

"I hope you feel at home," one of the prisoners said as the seven politicians were greeted in the gym of the country's biggest penitentiary, La Reforma, just outside the capital San Jose.

Costa Rica holds its presidential and legislative elections on 4 February, and the detention centre interaction was a way for the candidates to raise their profiles before campaigning started in earnest.

Prisoners have the right to vote.

The prisoners taking part were either serving short sentences or had displayed good conduct during their detention in Costa Rica.

The politicians included Antonio Alvarez Desanti, an opposition lawmaker currently ahead in voter intention surveys, as well as Carlos Alvarado, who stepped down as labour minister to make his tilt at the presidency.

One notable absentee from the debate was former security minister Juan Diego Castro, who is seen in second place in the opinion polls.

While a minister, he took a hard line stance against crime and against calls to reduce the prison population.

Costa Rica's current president, Luis Guillermo Solis, cannot seek re-election because the constitution bars consecutive terms.

The debate, organised by the University of Costa Rica, saw prisoners lob questions that included the situation of inmates and the rights of same-sex couples.

According to the justice ministry, the country - whose population is five million - has 36,038 prisoners.

Conditions in most of the penitentiaries have been found to be inadequate, with overcrowding a problem.