function run_hybrid_worker_for_phase_boundary_wrapper(batchIdx)
    a_s_list     = parse_environmental_variable('SCATTERING_LENGTH_RANGE', 85);  % Scattering length list
    theta        = parse_environmental_variable('POLAR_ANGLE_RANGE', 0);         % Single polar angle
    phi          = parse_environmental_variable('AZIMUTHAL_ANGLE_RANGE', 0);     % Single azimuthal angle
    N_atoms_list = parse_environmental_variable('NUM_ATOMS_LIST', 90000);        % Atom number list
    chunkSize    = str2double(getenv('CHUNK_SIZE'));

    % Validate matching list lengths
    if numel(a_s_list) ~= numel(N_atoms_list)
        error('Length of a_s_list and N_atoms_list must match.');
    end

    totalJobs = numel(a_s_list);
    totalBatches = ceil(totalJobs / chunkSize);

    if batchIdx > totalBatches
        error('Batch index %d exceeds total batches (%d)', batchIdx, totalBatches);
    end

    firstIdx = (batchIdx - 1) * chunkSize + 1;
    lastIdx  = min(batchIdx * chunkSize, totalJobs);

    % Construct the batch parameters
    batchParams = zeros(lastIdx - firstIdx + 1, 4); % Columns: a_s, theta, phi, N_atoms
    for i = 1:size(batchParams, 1)
        idx = firstIdx + i - 1;
        batchParams(i, :) = [a_s_list(idx), theta, phi, N_atoms_list(idx)];
    end

    % Call worker with this batch of parameters
    Scripts.run_hybrid_worker_for_phase_boundary(batchParams, batchIdx);
end

function vals = parse_environmental_variable(varName, default)
    str = getenv(varName);
    if isempty(str)
        vals = default;
    elseif startsWith(str, '[')
        vals = str2num(str); %#ok<ST2NM>
    else
        vals = eval(str);  % Trust only controlled environments
    end
end