Update values of objects for python script?
It's not working because closest_point_on_mesh expects its parameter p in Object Space, not in World Space. That is, the p's coordinates should be measured along the local axes of obj, taking into account obj's axes'location, rotation, and scale. closest_point_on_mesh also returns the location and normal of the closest point in the Object Space of obj.

So long as master is not transformed, its Object Space is the same as World Space, and isInside will work. But it will always compare the position of p to where master was before it was transformed. In order to measure p in master's space, we have to apply the inverse transformation to p as the one that was applied to master.. If you like, we pull master back to the world origin, and maintain the same relative position (rotation, scale) of p to master as it had before we pulled it back.

import bpy
import mathutils

def world_to_obj(point,obj):
    mat_obj_xform = obj.matrix_world
    mat_to_local = obj.matrix_world.inverted()
    return mat_to_local * point

def is_inside(point, obj):
    p = world_to_obj(point, obj)
    hit, hit_location, normal_at_location, face_index = obj.closest_point_on_mesh(p)
    ray = hit_location - p
    dotproduct = ray.dot(normal_at_location) 
    return (dotproduct &gt; 0.0)

green = bpy.data.materials.get("GREEN")
if green is None:
    green = bpy.data.materials.new(name="GREEN")
    green.diffuse_color = (0.0, 1.0, 0.0)

red = bpy.data.materials.get("RED")
if red is None:
    red = bpy.data.materials.new(name="RED")   
    red.diffuse_color = (1.0, 0.0, 0.0)

master = bpy.data.objects['Master']
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_pattern(pattern='Cube.*')

for cube in bpy.context.selected_objects:

    if is_inside(cube.location, master):
    #inside  
        if cube.data.materials:
            cube.data.materials[0] = green
        else:
            ob.data.materials.append(green)     
    else:
    #outside
        if cube.data.materials:
            cube.data.materials[0] = red
        else:
            cube.data.materials.append(red)     


Forgive the long-winded variable names and grubby code.. I meant them to be a bit more explanatory. (I've also stopped the repeat creation of materials.)