Senior civil servants could be forced to break the law and face the possibility of prosecution if they help Boris Johnson’s government defy the will of parliament, their union has warned.

After No 10’s insistence the government would not comply with an act designed to avoid a no-deal Brexit, the union has written to the prime minister demanding public assurances that Whitehall staff will not be asked to break the law or the civil service code.

In the letter obtained by the Guardian, Dave Penman, the FDA’s general secretary, wrote to Johnson saying the suggestion from No 10 that the government will ignore the settled will of parliament is causing increasing consternation in Whitehall.

“The endless speculation that government will refuse to implement an act of parliament may serve short-term political interest, but as prime minister your responsibilities go beyond tactical political game playing.

“Only you, as prime minister, can end this speculation. I am therefore asking you to categorically and publicly assure the civil service that no civil servant will be asked to breach their obligation under the civil service code to ‘comply with the law and uphold the administration of justice’,” he wrote.

Senior civil servants told the union they were concerned that if they assisted the government in defying the will of parliament as set out in legislation, they could be in breach of the law and therefore their code of conduct.

According to the civil service’s code of conduct, civil servants “must comply with the law and uphold the administration of justice”.

The union, which represents the UK’s most senior government officials, sought advice from a leading employment lawyer after receiving queries from dozens of members across several Brexit departments who were worried about their legal position.

Senior civil servants could face disciplinary action or even criminal charges in some circumstances if they complied with a government instruction to break the law, the lawyer warned. They could face a disciplinary panel or criminal charges such as malfeasance in a public office, the advice said.

The European Union (Withdrawal) (No. 2) Act, drawn up by a cross-party group of MPs against a no-deal outcome and given royal assent this week, mandates the prime minister to seek a further extension to Brexit beyond the current date of 31 October to 31 January next year – unless Johnson has either secured a deal with the EU that is acceptable to parliament, or MPs have voted for no deal before 19 October.

Downing Street has maintained that Johnson would neither resign, nor comply with the law to delay Brexit and has refused to explain how the apparent contradiction could be reconciled.

Reacting to the union’s letter, Dominic Grieve, the former attorney general who helped to draw up the rebel bill, said senior civil servants are deeply concerned by Downing Street’s threat of ignoring the law.

“I could well understand that civil servants are getting increasingly worried by the extraordinary words, statements and behaviour coming from No 10 Downing Street.

“Our constitution depends upon people observing rules of honesty and integrity and we seem to be losing them very quickly at present,” he said.

Legal advice obtained by Labour from Matrix Chambers warned that if Johnson defies the law, the civil service will be placed in an “invidious position in so far as they may be asked to take steps that are either contrary to the law or seek improperly to circumvent the law”.

Lord Kerslake, the former head of the civil service, said: “It is quite extraordinary that there is even a question of putting civil servants in a position where they could break the civil service code and that ministers are seriously contemplating breaking the law.

“This development confirms the very serious place we have now reached.”

The most senior official in each government department could seek a formal instruction called a ministerial direction if asked to commit an illegal act, the cross-bench peer said.

“Permanent secretaries, in their role as accounting officers, have a duty to seek a ministerial direction if their minister wishes to proceed with spending that they regard as illegal or poor value for money,” he said.

“There must surely be the prospect of such spending being incurred if a minister acts in a way that they know to be unlawful.”

Shami Chakrabarti, the shadow attorney general, said: “This is a scary moment for everyone, not least the law-abiding loyal public servants who are quite right to seek protection from a government out of control.”

According to a ComRes survey commissioned by the union, three-quarters (75%) of MPs recognise that attacks on the impartiality of the civil service have increased over the past three years, and agree that attacks on the civil service undermine public confidence and trust in the government (76%).

Downing Street was approached for a response.

• This article was amended on 12 September 2019 because an earlier version was incorrect to refer to Lord Kerslake as a Labour peer. He sits as a crossbencher.