How to scale primitive shapes in Blender so that they are within a [unit] sphere?
Use the bound box.


Result on Default cube scaled to fit in unit sphere

Half the length of one of the principal diagonals of the bounding box will be the radius of an encompassing sphere.

Simple test script.  Looks purely at local coordinates from the bounding box and scales such that will fit in local unit sphere.

Note this ensures they fit in a cuboid that fits in a sphere, not such that it fits perfectly into a sphere. 

import bpy
from mathutils import Vector

def bbox(ob):
    return (Vector(b) for b in ob.bound_box)

def bbox_center(ob):
    return sum(bbox(ob), Vector()) / 8

def bbox_radius(ob):
    bb = list(bbox(ob))
    return (bb[6] - bb[0]).length / 2

context = bpy.context
for ob in context.selected_objects:
    scale_factor = 1 / bbox_radius(ob)
    ob.scale *= scale_factor


Max vert from centroid.


Result on Cone

A similar method could be employed that looks at maximum distance from centroid on a per vertex basis.

def mesh_radius(ob):
    o = bbox_center(ob)
    return max((v.co - o).length for v in ob.data.vertices)

context = bpy.context
for ob in context.selected_objects:
    scale_factor = 1 / mesh_radius(ob)
    ob.scale *= scale_factor