diff --git a/lib/cdist/core/code.py b/lib/cdist/core/code.py
index 6dfa2da4..2345acc8 100644
--- a/lib/cdist/core/code.py
+++ b/lib/cdist/core/code.py
@@ -95,15 +95,16 @@ class Code(object):
     def _run_gencode(self, cdist_object, which):
         cdist_type = cdist_object.type
         script = os.path.join(self.local.type_path, getattr(cdist_type, 'gencode_%s_path' % which))
-        env = os.environ.copy()
-        env.update(self.env)
-        env.update({
-            '__type': cdist_object.type.absolute_path,
-            '__object': cdist_object.absolute_path,
-            '__object_id': cdist_object.object_id,
-            '__object_fq': cdist_object.path,
-        })
-        return self.local.run_script(script, env=env)
+        if os.path.isfile(script):
+            env = os.environ.copy()
+            env.update(self.env)
+            env.update({
+                '__type': cdist_object.type.absolute_path,
+                '__object': cdist_object.absolute_path,
+                '__object_id': cdist_object.object_id,
+                '__object_fq': cdist_object.path,
+            })
+            return self.local.run_script(script, env=env)
 
     def run_gencode_local(self, cdist_object):
         """Run the gencode-local script for the given cdist object."""