Bug Description
GitHub Issue: Cognee UI Frontend - EvalError in Next.js Middleware when running in Docker
Issue Title
cognee-cli -ui frontend throws "EvalError: Code generation from strings disallowed" in Docker environment
Description
When running the Cognee UI in a Docker container (using cognee/cognee:main image), the Next.js frontend fails to render pages due to an EvalError in the middleware. The backend API starts and works correctly, but the frontend returns HTTP 500 errors.
Environment
- Cognee Version: 0.4.1-local (from
cognee/cognee:main Docker image)
- Frontend Version: Downloaded from v0.3.7 release tag
- Node.js: v20.19.6
- Next.js: 15.3.3
- Docker: Docker Desktop on macOS (darwin 24.6.0)
- Container Base: Debian Bookworm (from cognee/cognee:main)
Analysis
The error Code generation from strings disallowed for this context is a security restriction in Node.js Edge Runtime that prevents dynamic code evaluation (like eval() or new Function()). This error originates from src/middleware.ts when compiled and executed in the Next.js edge runtime.
The middleware file likely contains code that:
- Uses dynamic string evaluation
- Or uses a library that internally uses
eval() or similar
Observed Behavior
| Component |
Status |
| Backend API (uvicorn) |
✅ Working - responds with {"message":"Hello, World, I am alive!"} |
| Frontend Next.js |
❌ 500 Error - middleware compilation fails |
Backend Works Correctly
$ curl http://localhost:8000/
{"message":"Hello, World, I am alive!"}
$ curl http://localhost:8000/health
# Returns health status
Relevant Logs
Frontend startup (success until middleware compilation)
[Cognee UI Frontend] Backend URL: http://cognee-api:8000
[Cognee UI Frontend] MCP URL: http://cognee:8001
[Cognee UI Frontend] Waiting for backend to be ready...
[Cognee UI Frontend] Backend is ready!
[Cognee UI Frontend] Starting Next.js on port 3000...
> cognee-frontend@1.0.0 dev
> next dev
⚠ You are using a non-standard "NODE_ENV" value in your environment.
▲ Next.js 15.3.3
- Local: http://localhost:3000
- Network: http://10.220.0.17:3000
✓ Starting...
○ Compiling /middleware ...
✓ Compiled /middleware in 3.4s (108 modules)
○ Compiling / ...
⨯ EvalError: Code generation from strings disallowed for this context
Docker Configuration
# docker-compose.yaml excerpt
cognee-ui:
image: cognee/cognee:main
ports:
- "8003:3000" # Frontend UI
environment:
NEXT_PUBLIC_BACKEND_API_URL: "http://cognee-api:8000"
NODE_ENV: "production"
Workarounds Attempted
- Running backend separately - Backend works fine when run directly with uvicorn
- Changing NODE_ENV - Tried "development" and "production", same error
- Using cognee-cli -ui - Same middleware error occurs
Possible Causes
src/middleware.ts may contain code incompatible with Edge Runtime
- A dependency used in middleware might use
eval() internally
- Next.js 15.3.3 has stricter Edge Runtime security than earlier versions
Suggested Fix
Review cognee-frontend/src/middleware.ts for:
- Any usage of
eval(), new Function(), or similar dynamic code execution
- Dependencies that might use string-based code generation
- Consider marking the middleware to run in Node.js runtime instead of Edge runtime if edge features aren't needed:
// In middleware.ts
export const config = {
runtime: 'nodejs', // Instead of default 'edge'
}
Or alternatively, ensure all code in middleware is Edge Runtime compatible.
Labels (suggested)
Steps to Reproduce
- Use Docker image
cognee/cognee:main
- Download frontend assets from GitHub release v0.3.7
- Run
npm install in the frontend directory
- Set
NEXT_PUBLIC_BACKEND_API_URL to point to a running Cognee API backend
- Run
npm run dev
- Access
http://localhost:3000 - returns HTTP 500
Alternatively (via cognee-cli)
- Inside a Docker container based on
cognee/cognee:main
- Run
cognee-cli -ui
- Backend starts successfully on port 8000
- Frontend starts on port 3000 but fails with the same EvalError
Expected Behavior
When running cognee-cli -ui or the Cognee frontend in a Docker container:
- The backend API should start and remain running (currently works ✅)
- The Next.js frontend should compile successfully without errors
- The frontend should be accessible at
http://localhost:3000 and render the Cognee UI
- Users should be able to interact with datasets, run cognify operations, and visualize knowledge graphs through the web interface
Actual Behavior
- The backend API starts correctly and responds to requests ✅
- The Next.js frontend begins compilation but fails during middleware execution ❌
- Accessing
http://localhost:3000 returns HTTP 500 Internal Server Error ❌
- The error
EvalError: Code generation from strings disallowed for this context is thrown from middleware.ts
Environment
OS: Linux 6.10.14-linuxkit (Docker on macOS)
Node: v20.19.6
Next.js: 15.3.3
Cognee: 0.4.1-local (cognee/cognee:main image)
Python: 3.12.12
Logs/Error Messages
⨯ EvalError: Code generation from strings disallowed for this context
at <unknown> (.next/server/middleware.js:18)
at (middleware)/./node_modules/next/dist/build/webpack/loaders/next-middleware-loader.js?absolutePagePath=%2Froot%2F.cognee%2Fui-cache%2Ffrontend%2Fsrc%2Fmiddleware.ts&page=%2Fmiddleware&rootDir=%2Froot%2F.cognee%2Fui-cache%2Ffrontend&matchers=&preferredRegion=&middlewareConfig=e30%3D! (.next/server/middleware.js:18:1)
at __webpack_require__ (.next/server/edge-runtime-webpack.js:37:33)
at __webpack_exec__ (.next/server/middleware.js:1043:48)
at <unknown> (.next/server/middleware.js:1044:37)
at webpackJsonpCallback (.next/server/edge-runtime-webpack.js:1128:39)
at <unknown> (.next/server/middleware.js:9:61)
Additional Context
This issue was discovered while setting up Cognee with a custom XTDB 2.0 graph database adapter in a Docker-based development environment. The backend (cognee.api.client) works perfectly; only the frontend has this issue.
Related: cognee-cli -ui subprocess issue
Separately, we also observed that cognee-cli -ui has an issue where the backend subprocess dies silently after startup (no supervision/restart). This is a separate issue but makes Docker deployment challenging. The recommended workaround is to run backend and frontend as separate services rather than using cognee-cli -ui as a process manager.
Pre-submission Checklist
Bug Description
GitHub Issue: Cognee UI Frontend - EvalError in Next.js Middleware when running in Docker
Issue Title
cognee-cli -uifrontend throws "EvalError: Code generation from strings disallowed" in Docker environmentDescription
When running the Cognee UI in a Docker container (using
cognee/cognee:mainimage), the Next.js frontend fails to render pages due to an EvalError in the middleware. The backend API starts and works correctly, but the frontend returns HTTP 500 errors.Environment
cognee/cognee:mainDocker image)Analysis
The error
Code generation from strings disallowed for this contextis a security restriction in Node.js Edge Runtime that prevents dynamic code evaluation (likeeval()ornew Function()). This error originates fromsrc/middleware.tswhen compiled and executed in the Next.js edge runtime.The middleware file likely contains code that:
eval()or similarObserved Behavior
{"message":"Hello, World, I am alive!"}Backend Works Correctly
$ curl http://localhost:8000/ {"message":"Hello, World, I am alive!"} $ curl http://localhost:8000/health # Returns health statusRelevant Logs
Frontend startup (success until middleware compilation)
Docker Configuration
Workarounds Attempted
Possible Causes
src/middleware.tsmay contain code incompatible with Edge Runtimeeval()internallySuggested Fix
Review
cognee-frontend/src/middleware.tsfor:eval(),new Function(), or similar dynamic code executionOr alternatively, ensure all code in middleware is Edge Runtime compatible.
Labels (suggested)
buguidockernext.jsSteps to Reproduce
cognee/cognee:mainnpm installin the frontend directoryNEXT_PUBLIC_BACKEND_API_URLto point to a running Cognee API backendnpm run devhttp://localhost:3000- returns HTTP 500Alternatively (via cognee-cli)
cognee/cognee:maincognee-cli -uiExpected Behavior
When running
cognee-cli -uior the Cognee frontend in a Docker container:http://localhost:3000and render the Cognee UIActual Behavior
http://localhost:3000returns HTTP 500 Internal Server Error ❌EvalError: Code generation from strings disallowed for this contextis thrown frommiddleware.tsEnvironment
OS: Linux 6.10.14-linuxkit (Docker on macOS)
Node: v20.19.6
Next.js: 15.3.3
Cognee: 0.4.1-local (cognee/cognee:main image)
Python: 3.12.12
Logs/Error Messages
Additional Context
This issue was discovered while setting up Cognee with a custom XTDB 2.0 graph database adapter in a Docker-based development environment. The backend (cognee.api.client) works perfectly; only the frontend has this issue.
Related: cognee-cli -ui subprocess issue
Separately, we also observed that
cognee-cli -uihas an issue where the backend subprocess dies silently after startup (no supervision/restart). This is a separate issue but makes Docker deployment challenging. The recommended workaround is to run backend and frontend as separate services rather than usingcognee-cli -uias a process manager.Pre-submission Checklist