'context' error when trying to bevel an object with Python
You should avoid using ops when possible, see here. As for you code:

import bpy

# generate the cube and make it selected and active:
verts = [(-1.0, -1.0, -1.0), (-1.0, -1.0, 1.0), 
    (-1.0, 1.0, -1.0), (-1.0, 1.0, 1.0), (1.0, -1.0, -1.0),
    (1.0, -1.0, 1.0), (1.0, 1.0, -1.0), (1.0, 1.0, 1.0)]

faces = [(0, 1, 3, 2), (2, 3, 7, 6), 
        (6, 7, 5, 4), (4, 5, 1, 0),
        (2, 6, 4, 0), (7, 3, 1, 5)]

me = bpy.data.meshes.new('Cube')
ob = bpy.data.objects.new('Cube', me)
bpy.context.scene.objects.link(ob)
ob.select = True
bpy.context.scene.objects.active = ob
me.from_pydata(verts, [], faces)
me.update() 

# bevel the cube
bevel_mod = ob.modifiers.new('Bevel', 'BEVEL')
bevel_mod.width = 0.2
bevel_mod.segments = 5
bevel_mod.profile = 0.7
bevel_mod.material = -1
# we use ops here since there is really no other way
bpy.ops.object.modifier_apply(apply_as='DATA', modifier=bevel_mod.name)