diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 0fd958846440c2767af850550fa636b1707db665..e00a07d3b1a0666a60f7d12c4164b0095a4083ee 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -1778,10 +1778,11 @@ void DerivationGoal::startBuilder()
         if (passAsFile.find(i.first) == passAsFile.end()) {
             env[i.first] = i.second;
         } else {
-            Path p = tmpDir + "/.attr-" + std::to_string(fileNr++);
+            string fn = ".attr-" + std::to_string(fileNr++);
+            Path p = tmpDir + "/" + fn;
             writeFile(p, i.second);
             filesToChown.insert(p);
-            env[i.first + "Path"] = p;
+            env[i.first + "Path"] = tmpDirInSandbox + "/" + fn;
         }
     }