diff --git a/Haskintex.hs b/Haskintex.hs
--- a/Haskintex.hs
+++ b/Haskintex.hs
@@ -34,9 +34,10 @@
 import Paths_haskintex (version)
 import Data.Version (showVersion)
 -- Lists
-import Data.List (intersperse)
+import Data.List (intersperse, isSuffixOf)
 -- GHC
 import Language.Haskell.Interpreter hiding (get)
+import Language.Haskell.Interpreter.Unsafe (unsafeRunInterpreterWithArgs)
 import Data.Typeable
 import qualified Language.Haskell.Exts.Pretty as H
 import qualified Language.Haskell.Exts.Parser as H
@@ -100,6 +101,7 @@
   , memoFlag      :: Bool
   , memocleanFlag :: Bool
   , autotexyFlag  :: Bool
+  , nosandboxFlag :: Bool
   , unknownFlags  :: [String]
   , inputs        :: [FilePath]
   , memoTree      :: MemoTree
@@ -119,10 +121,11 @@
   , ("memo"      , memoFlag)
   , ("memoclean" , memocleanFlag)
   , ("autotexy"  , autotexyFlag)
+  , ("nosandbox" , nosandboxFlag)
     ]
 
 readConf :: [String] -> Conf
-readConf = go $ Conf False False False False False False False False False False False False [] [] M.empty
+readConf = go $ Conf False False False False False False False False False False False False False [] [] M.empty
   where
     go c [] = c
     go c (x:xs) =
@@ -142,6 +145,7 @@
              "memo"      -> go (c {memoFlag      = True}) xs
              "memoclean" -> go (c {memocleanFlag = True}) xs
              "autotexy"  -> go (c {autotexyFlag  = True}) xs
+             "nosandbox" -> go (c {nosandboxFlag = True}) xs
              _           -> go (c {unknownFlags = unknownFlags c ++ [flag]}) xs
         -- Otherwise, an input file.
         _ -> go (c {inputs = inputs c ++ [x]}) xs
@@ -288,7 +292,22 @@
              setTopLevelModules [modName]
              setImports ["Prelude"]
              interpret e ty
-      r <- runInterpreter int
+      -- Sandbox recognition
+      inSandbox <- lift $ doesDirectoryExist ".cabal-sandbox"
+      r <- if inSandbox
+              then do outputStr "Sandbox detected."
+                      noSandbox <- nosandboxFlag <$> get
+                      if noSandbox
+                         then do outputStr "Ignoring sandbox."
+                                 runInterpreter int
+                         else do sand <- lift $ getDirectoryContents ".cabal-sandbox"
+                                 let pkgdbs = filter (isSuffixOf "packages.conf.d") sand
+                                 case pkgdbs of
+                                   pkgdb : _ -> do
+                                     outputStr $ "Using sandbox package db: " ++ pkgdb
+                                     unsafeRunInterpreterWithArgs ["-package-db .cabal-sandbox/" ++ pkgdb] int
+                                   _ -> runInterpreter int
+              else runInterpreter int
       case r of
         Left err -> do
           outputStr $ "Warning: Error while evaluating the expression.\n"
@@ -654,6 +673,8 @@
   , "              or iohatex command. This effectively allows the user to write"
   , "              expressions in types other than LaTeX and have haskintex to perform"
   , "              the required transformation."
+  , ""
+  , "  -nosandbox  Do not use the sandbox package db even in the presence of one."
   , ""
   , "Any unsupported flag will be ignored."
   ]
diff --git a/haskintex.cabal b/haskintex.cabal
--- a/haskintex.cabal
+++ b/haskintex.cabal
@@ -1,5 +1,5 @@
 name:                haskintex
-version:             0.5.1.0
+version:             0.6.0.0
 synopsis:            Haskell Evaluation inside of LaTeX code.
 description:
   The /haskintex/ (Haskell in LaTeX) program is a tool that reads a LaTeX file and evaluates Haskell expressions contained
@@ -9,7 +9,13 @@
   You can freely add any Haskell code you need, and make this code appear /optionally/ in the LaTeX output. It is a tiny program,
   and therefore, easy to understand, use and predict.
   .
-  Addition from last version: new flag autotexy. See project homepage for description.
+  Additions from last version:
+  .
+  * /haskintex/ is now able to detect that is running on a cabal sandbox, and will use the sandbox package
+    db if this is the case. Unless the flag @-nosandbox@ is given, in which case the sandbox will be ignored.
+  .
+  * New flag @-nosandbox@. Ignore sandbox if /haskintex/ runs on one.
+  .
 homepage:            http://daniel-diaz.github.io/projects/haskintex
 bug-reports:         https://github.com/Daniel-Diaz/haskintex/issues
 license:             BSD3
