What criteria does a sandbox use to determine whether executing code (registry read/write) can be trusted or not ?
A well-designed sandbox is simple: all code inside it is untrusted, and has to ask the sandbox if it wants access to anything outside.
A sandbox is an environment which restricts what the code can do. Such restrictions might for example limit file access to specific directories, network access to specific IP or ports or use of system calls to only white listed ones. What kind of restrictions are setup for the sandbox depends on the specific use case.
And because the sandbox restricts what code can do it can be used to execute untrusted code, i.e. code which might be harmful when run within an unrestricted environment. In other words: the sandbox does not distinguish between untrusted and trusted code. Instead every code inside the sandbox is considered untrusted and that's the reason it will be run inside a sandbox in the first place.