What APIs is the `security` cli using?
AuthorizationExecuteWithPrivileges
security uses the deprecated AuthorizationExecuteWithPrivileges function to implement execute-with-privileges:
status = AuthorizationExecuteWithPrivileges(auth_ref,argv[0], 0, (argc &gt; 1) ? &amp;argv[1] : NULL, &amp;communications_pipe);

The function needs an AuthorizationRef, which is the part that confirms who the user is. See the AuthorizationServices framework. Note that AuthorizationServices are not available to sandboxed applications on macOS.
Open Source
security is open source and available on https://opensource.apple.com
macOS 10.15.3's Security-59306.80.4 bundle contains the source code:

Security-59306.80.4/SecurityTool/macOS