Hungary has approved legislation ordering the automatic detention of all asylum seekers and refugees in shipping container camps on the country's southern borders.

The new law was approved by a majority of politicians just weeks after the Hungarian government announced the construction of a fence along the southern border to stop migrants from freely entering the country.

The tough new measures have been introduced in response to recent terror attacks carried out by migrants across Europe, Hungary's far-right Prime Minister Viktor Orban said.

The new legislation would allow all asylum seekers entering the country, as well as those already in Hungary, to be detained or moved to container camps and would prevent their freedom to move around or leave the country while their asylum application is processed.

"Containers suitable for accommodating 200-300 people will be erected. Migrants will have to wait there for a legally binding decision on their claims," government spokesperson Janos Lazar confirmed.

"In the future, illegal immigrants must wait for the verdict on their asylum case in designated transit zones at the border," the bill, published on the Hungarian parliament's website, read.

A UNHCR spokesperson said she was "deeply concerned" by the government's decision, commenting that it "will have a terrible physical and psychological impact on women, children and men who have already greatly suffered." She added that the new legislation would make it "nearly impossible for asylum seekers to enter the country, apply for asylum and receive international protection."

Amnesty International's deputy director for Europe, Gauri van Gulik, said: "Rounding up all men, women and children seeking asylum and detaining them for months on end in container camps is a new low in Hungary's race to the bottom on asylum seekers and refugees."

Hungary Serbia border
Border soldiers patrol along the fence on the Hungarian-Serbian border Attila Kisbenedek/AFP

The decision to detain refugees in shipping containers was taken just weeks after the government announced an electrified fence is being constructed along the Serbian-Hungarian border, with completion due by 1 May.

A government spokesperson stressed that the fence was "protecting the European Union, not Hungary". Lazar said that the new "intelligent fence" had much greater technical capabilities that the existing barbed wire fence along the Hungarian border with Serbia and Croatia.

"Thanks to the new technology, a low voltage, and completely safe current will also be flowing through the fence, which will send an alarm to border control authorities if any attempts are made to damage the fence," he said.

"The goal to be realised by the fence is exactly what the Austrians want too, that nobody is able to cross the border who will need to be sent back later because they are in the EU illegally."