China and the US are working on a “code of conduct” for online espionage and hacking after months of trading accusations over cyber attacks.

Officials in Washington have claimed a hack that stole the personal details of up to four million government employees originated in China but Beijing said denied the accusations and called them “not responsible and counterproductive”.

It was among the alleged attacks leading to what John Kerry described as “very frank discussions” between the two countries over three days of talks.

US surveillance revealed the extent of Chinese construction in the disputed South China Sea (REUTERS/U.S. Navy/Handout via Reuters/Files)

President Barack Obama ended the Security and Economic Dialogue by raising concerns to the Chinese delegation about the nation’s “cyber and maritime behaviour” in the South China Sea.

“He urged China to take concrete steps to lower tensions,” a White House spokesperson said in a statement.

Mr Kerry, the US Secretary of State, met with senior Chinese politicians and diplomats yesterday to discuss trade, finance, climate change and the “standards of behaviour in cyber space”.

He said: “The United States is deeply concerned about cyber incursions that have raised security questions and, frankly, harmed American businesses.

“We believe very strongly that the United States and China should be working together to develop and implement a shared understanding of appropriate state behaviour in cyber space, and I’m pleased to say that China agreed that we must work together to complete a code of conduct regarding cyber activities.”

The FBI is investigating the source of the hack of systems at the Office of Personnel Management (AFP/Getty Images)

Mr Kerry acknowledged that the US and China have “not always seen eye to eye” but have a “mature and good working relationship” that can overcome those difficulties.

The President had raised the issue of cyber attacks directly with his Chinese counterpart Xi Jinping when he last visited the US in 2013 but allegations of state-backed theft and espionage have only intensified.

State Councillor Yang Jiechi insisted that China cracks down on hacking and is ready to co-operate with the US on cyber security, urging Washington “respect facts”.

Diplomats from Beijing also rebuffed criticism of its conduct in the South China Sea, where China has controversially built a number of artificial islands and raised tensions in the territorial dispute with several neighbouring countries..

“There is no crisis in the South China Sea,” said Zheng Zeguang, assistant minister of foreign affairs, adding that China's behaviour was “beyond reproach”, especially from the US as it not a party in the dispute.

China's territorial disputes Show all 5 1 /5 China's territorial disputes China's territorial disputes South China Sea A satellite image of what is claimed to be an under-construction airstrip at Fiery Cross Reef in the Spratly Islands in the disputed South China Sea China's territorial disputes South China Sea Chinese dredging vessels are purportedly seen in the waters around Mischief Reef China's territorial disputes South China Sea A Chinese Guided Missile Frigate Hengshui docked at a port in Yalong Bay in Sanya, south China's Hainan Province. China's military compared its controversial island reclamation project in the South China Sea to ordinary construction going on in other parts of the country, such as the building of roads and apartments China's territorial disputes South China Sea The alleged on-going land reclamation of China at Subi reef is seen from Pagasa island (Thitu Island) in the Spratlys group of islands in the South China Sea, west of Palawan, Philippines China's territorial disputes South China Sea U.S. military forces aboard Amphibious Assault Vehicles (AAV) manuevre on South China Sea near the shore of San Antonio, Zambales during the annual "Balikatan" (shoulder-to-shoulder) war games with Filipino soldiers in northern Philippines. The U.S. Marine Corps is bringing together foreign commanders from amphibious forces deployed mostly in the Asia-Pacific for a conference aimed at taking initial steps to integrate their operations, with China excluded from the event, according to officials and planning documents

Despite their differences on maritime security, the US and China said Wednesday are stepping up co-operation on conservation, climate change and combating illegal fishing in the North Pacific.

There was also progress on US concerns that the Chinese renminbi is undervalued against the dollar.

Xinhua, China’s state-run news agency, said the two nations “agreed on a number of issues, and disagreed on a string of problems too” but said there was willingness to address their differences.

Its report made a comparatively brief mention of “commercial cyber attacks”, listing them among the “thorny” issues on the table.

“The conclusion of the seventh round of the dialogue is a new beginning,” it added.

“With Chinese President Xi Jinping's upcoming visit to the United States, the China-US economic ties are expected to enter a new phase and the two people will benefit more.”