You can retrieve cloud code with CloudGet or CloudImport:
obj = CloudPut[Hold[f[x_] := x^2;], IncludeDefinitions -> True];
ClearAll[f];
ReleaseHold[CloudGet[obj]];
f[3]
(I included the ClearAll[f] to be absolutely sure that the definition for f was being pulled from the cloud and not locally.) If you then wanted to save the definition of f locally, you could save the output of Definition[f] to a file.
Also, you can download the source code of a resource function by clicking the 'Source Notebook' button. And while resource functions are not "official" Wolfram Language functions, many are provided by Wolfram staff and are quite robust.