Callback function is being called twice

The issue is not with your code. It is due to how WordPress works internally. This has been reported as bug in 2012 (almost 10 years ago at this point).

You can see the bug report here: https://core.trac.wordpress.org/ticket/21989

The thing is that update_option is called, which when the option does not exist, will call add_option first. Now this makes this weird 2-time-pass.

To “live with it” you can do several different things. The best might be to check your option as well as the input.

In the way how I make my options, for me it is as simple as checking for one of the keys I know will be present. It ends up being either available or within an array.

public function checkboxSanitize($input) {

    if(!isset($input['known_key']) && isset($input[0],$input[0]['known_key'])) {
        $input = $input[0];
    }
    //...
}

Another, also simple way to check is to define some constant and then check it up if defined. In most cases it would not fire.

public function checkboxSanitize($input) {

    if(defined('CHECKBOXES_SANITIZED')) {
        // handle differently
        // For example, do not call any APIs again, just build and save option
    }

    define('CHECKBOXES_SANITIZED', true);

    //...
}

I do want to point out anyone new to WP that finds this. Please make note that on second pass, you do not necessarily have anything saved, so if you just exist the function at that time, you might end up with no value saved.

Instead you are likely going to want to handle it (again). Also skipping first time is not ideal, since it might only fire once in some cases. In which case you would again end up without any value saved.

PS: I know this has been asked a bit back, however as I myself end up from time to time with a search to remember why exactly this is happening and this question has no answer, wanted to add it.