Refusing to give a job to Chinese and Russian people in companies that deal with issues of national security and require security clearance is not racist, an employment tribunal has ruled.
It is not discriminatory to stop people from "hostile" states taking up certain jobs in the defence sector because of the risk to British security, the judgment says.
The ruling relates to the case of a Chinese scientist who accused a British AI company with ties to the UK and US defence departments of racism after she was not given a job due to security concerns.
Tianlin Xu applied for a role at Binary AI Ltd but the founder of the software company, James Patrick-Evans, turned her down and employed a British man instead.
He emailed her: "Disappointingly I've come to the decision not to proceed with your application on the sole basis of your nationality.
"As a company, we work closely in sensitive areas with western governments and wish to continue to do so. We're simply not big enough of a company to ensure the separation and security controls needed to hire someone of your nationality at this stage."
Judge Richard Baty, sitting in London, described the email as clumsy and said: "In complete isolation, it looks like an admission of direct race discrimination on the basis of nationality."
But he said in fact Xu had been turned down as she would not get security clearance because of her nationality.
The judge said: "That reason would apply to people of any nationality where it was not possible to get security clearance (including Russian, North Korean and Iranian nationality as well as Chinese nationality). The reason is not nationality per se."
Patrick-Evans was "strongly advised against hiring a Chinese national" by defence officials that he worked with, the tribunal heard.
Binary AI had had a contract with the Defence Science and Technology Laboratory - the secret site based at Porton Down in Wiltshire - and the Ministry of Defence to develop AI that could identify hidden "back doors" inside software.
Baty said in his judgment: "It is obvious that software drives the modern world. It underpins our everyday lives and runs every sector of our state.
"Therefore, it is paramount that the security and operational capability of the software that drives our everyday lives should remain intact and free from malicious hackers and state actors wanting to persuade political outcomes or obtain sensitive information."
Xu's complaints of direct and indirect race discrimination both failed.