Sweden is to spend 10m kronor ($1.5m; £937,000) on guidelines for overseas government officials, outlining inappropriate sexual behaviour.
Areas covered by the code may include the buying of sex by officials abroad or "improper" relationships in developing countries.
The gender equality ministry said a review ruled that not all departments had the necessary guidelines.
The money will also pay for a website and seminars for staff.
Sweden has a Sex Purchase Law - the Sexkopslagen - which makes it a crime to pay for sex, although selling sex remains legal.
However, incidents in which Swedes have paid for sex abroad, where they were not breaking local laws, have sparked an ethical debate in the country, correspondents say.
The aim is for "government agencies to have ethical guidelines concerning civil servants abroad in regard to purchasing sexual services," said Yoav Bartal, spokesman for the Ministry of Gender Equality.
"They will describe what behaviour is not acceptable and what the consequences will be if they are breached," he told the BBC.
Mr Bartal said that the media had highlighted the case of UN peacekeepers who had exploited the local population in DR Congo.
"When it comes to when you are working in a country that's affected by war and hunger and poverty it might be inappropriate to have relations with the population where people are dependent on aid," he said.
Gender Equality Minister Nyamko Sabuni said that government departments needed "clarity" if they had to deal with employees who bought sexual services abroad.
"It is clear that everyone knows that you cannot buy sex, surf for porn during work hours, or come as a rich man or woman and sexually exploit someone living in poverty. That much we know.
"But it must be made clear in a document what you can do and cannot do," Ms Sabuni said, according to the Local news website.
But she said the government was loathe to set down one set of rules for all departments.
"Different agencies have different needs," she told the newspaper.
"You can't compare the military in peace-promoting missions with agencies which maybe only travel to Brussels."