diff --git a/pyproject.toml b/pyproject.toml
index bdb2b26779abbf1784c5aeaf2b9a2cf96965649c..030dc7b1e6ad1358defdaa1a63a0e58535539cd8 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -7,6 +7,7 @@ dependencies = [
     "losoto",
     "numpy",
     "pandas",
+    "psutil",
 ]
 
 [project.optional-dependencies]
diff --git a/scripts/query_memory.py b/scripts/query_memory.py
new file mode 100755
index 0000000000000000000000000000000000000000..df920c67de8df51a09a7cdaea8513bf24c019681
--- /dev/null
+++ b/scripts/query_memory.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+import argparse
+import json
+import psutil
+import sys
+
+
+def main(memory_percentage):
+    """
+    Computes memory_percentage percent of the available virtual memory.
+    Writes the amount of available memory to a dictionary.
+    """
+
+    # psutil outputs the memory in bytes. This is converted into
+    # mebibytes (1 MiB = 2^20 B) to match CWL's ResourceRequirement input.
+    required_memory = int(
+        psutil.virtual_memory().available / 2**20 * memory_percentage / 100
+    )
+
+    result = {"memory": required_memory}
+
+    with open("./memory.json", "w") as fp:
+        json.dump(result, fp)
+
+    return result
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser()
+    parser.add_argument("memory_percentage", type=int)
+    main(parser.parse_args().memory_percentage)
diff --git a/steps/get_memory_fraction.cwl b/steps/get_memory_fraction.cwl
index f96d348ae6ba8c33fb0a615b845bf3850783021c..c47b844b5265cb59c9cd22561a6b5725a9b4742e 100644
--- a/steps/get_memory_fraction.cwl
+++ b/steps/get_memory_fraction.cwl
@@ -7,15 +7,15 @@ doc: |
     This is used to ensure that flagging jobs don't exceed the
     node's resources.
 
-baseCommand:
-    - python3
-    - query_memory.py
+baseCommand: query_memory.py
 
 stdout: memory.txt
 
 inputs:
     - id: fraction
       type: int 
+      inputBinding:
+        position: 1
       doc: |
         The required fraction of the node's
         available memory for a flagging job.
@@ -37,20 +37,4 @@ hints:
 
 requirements:
     - class: InlineJavascriptRequirement
-    - class: InitialWorkDirRequirement
-      listing:
-        - entryname: query_memory.py
-          entry: |
-            import json
-            import psutil
 
-            # psuitil outputs the memory in bytes.
-            # This is converted into mebibytes (1 MiB = 2^20 B)
-            # to match CWL's ResourceRequirement input.
-            required_memory = int(psutil.virtual_memory().available / 2**20
-                                    * $(inputs.fraction) / 100)
-            print("The available memory is ", required_memory)
-            result = {"memory" : required_memory}
-
-            with open('./memory.json', 'w') as fp:
-                json.dump(result, fp)