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 but every code inside the sandbox is considered untrusted.