diff --git a/core/swiftAction/Dockerfile b/core/swiftAction/Dockerfile
index e2a4acbb6c288b5ba10bda5d5b2b644cfc6786cf..94831afcfb3422c6954afd508f4afd6616bd7405 100644
--- a/core/swiftAction/Dockerfile
+++ b/core/swiftAction/Dockerfile
@@ -35,11 +35,11 @@ RUN SWIFT_ARCHIVE_NAME=swift-$SWIFT_VERSION-$SWIFT_PLATFORM && \
 # Copy the Flask proxy. Following the pattern in nodejsAction.
 ADD . /swiftAction
 
-RUN cd /swiftAction; rm -rf .project .settings build.xml Dockerfile 
+RUN cd /swiftAction; rm -rf .project .settings build.xml Dockerfile
 
 # Where the script will live.
-RUN mkdir -p /swiftActionSource
-RUN touch /swiftActionSource/action.swift
+RUN mkdir -p /swiftAction
+RUN touch /swiftAction/action.swift
 
 ENV FLASK_PROXY_PORT 8080
 
diff --git a/core/swiftAction/proxy.py b/core/swiftAction/proxy.py
index e298465fc4058bc32c8956f647d4d09ff42e5175..64aab2368f2291828614baad3e4c7365ad66e298 100644
--- a/core/swiftAction/proxy.py
+++ b/core/swiftAction/proxy.py
@@ -28,8 +28,11 @@ proxy = flask.Flask(__name__)
 proxy.debug = False
 
 SRC_EPILOGUE_FILE = "./epilogue.swift"
-DEST_SCRIPT_FILE = "/swiftActionSource/action.swift"
-PROCESS = [ "swift", DEST_SCRIPT_FILE ]
+DEST_SCRIPT_FILE = "/swiftAction/action.swift"
+DEST_BIN_FILE = "/swiftAction/action"
+BUILD_PROCESS = [ "swiftc", "-O", DEST_SCRIPT_FILE, "-o", DEST_BIN_FILE ]
+# RUN_PROCESS = [ "swift", DEST_SCRIPT_FILE ]
+RUN_PROCESS = [ DEST_BIN_FILE ]
 
 @proxy.route("/init", methods=['POST'])
 def init():
@@ -44,6 +47,22 @@ def init():
             fp.write(str(message["code"]))
             with codecs.open(SRC_EPILOGUE_FILE, "r", "utf-8") as ep:
                 fp.write(ep.read())
+
+        p = subprocess.Popen(BUILD_PROCESS)
+
+        (o,e) = p.communicate()
+
+        if o is not None:
+            sys.stdout.write(o)
+
+        if e is not None:
+            sys.stderr.write(e)
+
+        if not (os.path.isfile(DEST_BIN_FILE) and os.access(DEST_BIN_FILE, os.X_OK)):
+            response = flask.jsonify({"error": "the action failed to compile. See logs for details." })
+            response.status_code = 502
+            return response
+
         return ('OK', 200)
     else:
         flask.abort(403)
@@ -63,10 +82,15 @@ def run():
     if not isinstance(value, dict):
         flask.abort(403)
 
+    if not (os.path.isfile(DEST_BIN_FILE) and os.access(DEST_BIN_FILE, os.X_OK)):
+        response = flask.jsonify({ "error": "the action failed to compile. See logs for details." })
+        response.status_code = 502
+        return response
+
     swift_env_in = { "WHISK_INPUT" : json.dumps(value) }
 
     p = subprocess.Popen(
-        PROCESS,
+        RUN_PROCESS,
         stdin=subprocess.PIPE,
         stdout=subprocess.PIPE,
         env=swift_env_in)
@@ -93,13 +117,13 @@ def run():
             response = flask.jsonify(json_output)
             return response
         else:
-            reponse = { "error": "the action did not return an object", "action_output": json_output }
-            reponse.status_code = 502
+            response = flask.jsonify({ "error": "the action did not return an object", "action_output": json_output })
+            response.status_code = 502
             return response
-    except:
-        sys.stderr.write("Couldn't parse Swift script output as JSON: %s.\n" % last_line)
-        json_output = { "error": "the action did not return a valid result" }
-        response = flask.jsonify(json_output)
+    except Exception as e:
+        # sys.stderr.write("Couldn't parse Swift script output as JSON: %s.\n" % last_line)
+        # sys.stderr.write("%s\n%s\n" % (str(e),repr(e)))
+        response = flask.jsonify({ "error": "the action did not return a valid result" })
         response.status_code = 502
         return response
 
diff --git a/tests/src/actionContainers/SwiftActionContainerTests.scala b/tests/src/actionContainers/SwiftActionContainerTests.scala
index cb9ba68ff78da4ff848ef602328f539fd248c123..58d4c93bd68deb4107c2803c8b37c0b813136797 100644
--- a/tests/src/actionContainers/SwiftActionContainerTests.scala
+++ b/tests/src/actionContainers/SwiftActionContainerTests.scala
@@ -72,8 +72,13 @@ class SwiftActionContainerTests extends FlatSpec
     it should "return some error on action error" in {
         withSwiftContainer { c =>
             val code = """
+                | // You need an indirection, or swiftc detects the div/0
+                | // at compile-time. Smart.
+                | func div(x: Int, _ y: Int) -> Int {
+                |     return x/y
+                | }
                 | func main(args: [String: Any]) -> [String: Any] {
-                |     return [ "divBy0": 5/0 ]
+                |     return [ "divBy0": div(5,0) ]
                 | }
             """.stripMargin
 
@@ -96,18 +101,15 @@ class SwiftActionContainerTests extends FlatSpec
             """.stripMargin
 
             val (initCode, _) = c.init(initPayload(code))
+            initCode should not be(200)
 
-            // Unfortunately we don't know how to test valid Swift code for now.
-            // initCode should not be(200)
-
-            val (runCode, _) = c.run(runPayload(JsObject("basic" -> JsString("forever"))))
-
+            val (runCode, runRes) = c.run(runPayload(JsObject("basic" -> JsString("forever"))))
             runCode should be(502)
         }
-
         err.toLowerCase should include("error")
     }
 
+
     it should "support application errors" in {
         withSwiftContainer { c =>
             val code = """
@@ -129,16 +131,14 @@ class SwiftActionContainerTests extends FlatSpec
 
     it should "enforce that the user returns an object" in {
         withSwiftContainer { c =>
-            // Funny how type inference lets you omit the return type and shoot
-            // yourself in the foot here.
             val code = """
-                | func main(args: [String: Any]) {
+                | func main(args: [String: Any]) -> String {
                 |     return "rebel, rebel"
                 | }
             """.stripMargin
 
             val (initCode, _) = c.init(initPayload(code))
-            initCode should be(200)
+            initCode should be(200) // This could change if the action wrapper has strong type checks for `main`.
 
             val (runCode, runRes) = c.run(runPayload(JsObject()))
             runCode should be(502)