The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat: default code interpreter and logic function to Disabled in production (#18559)
Félix Malfaitf0c83434a7ee
diff --git a/packages/twenty-docs/developers/self-host/capabilities/setup.mdx b/packages/twenty-docs/developers/self-host/capabilities/setup.mdxindex 5bb2f81c2e9..975d59e28f2 100644--- a/packages/twenty-docs/developers/self-host/capabilities/setup.mdx+++ b/packages/twenty-docs/developers/self-host/capabilities/setup.mdx@@ -289,43 +289,57 @@ yarn command:prod cron:workflow:automated-cron-trigger**Environment-only mode:** If you set `IS_CONFIG_VARIABLES_IN_DB_ENABLED=false`, add these variables to your `.env` file instead.</Warning>-## Logic Functions+## Logic Functions & Code Interpreter-Twenty supports logic functions for workflows and custom logic. The execution environment is configured via the `SERVERLESS_TYPE` environment variable.+Twenty supports logic functions for workflows and the code interpreter for AI data analysis. Both run user-provided code and require explicit configuration for security.++### Security Defaults++**In production (NODE_ENV=production):** Both logic functions and code interpreter default to **Disabled**. You must explicitly enable them with `LOGIC_FUNCTION_TYPE` and `CODE_INTERPRETER_TYPE` if you need these features.++**In development (NODE_ENV=development):** Both default to **LOCAL** for convenience when running locally.<Warning>-**Security Notice:** The local driver (`SERVERLESS_TYPE=LOCAL`) runs code directly on the host in a Node.js process with no sandboxing. It should only be used for trusted code in development. For production deployments handling untrusted code, we highly recommend using `SERVERLESS_TYPE=LAMBDA` or `SERVERLESS_TYPE=DISABLED`.+**Security Notice:** The local driver (`LOGIC_FUNCTION_TYPE=LOCAL` or `CODE_INTERPRETER_TYPE=LOCAL`) runs code directly on the host in a Node.js process with no sandboxing. It should only be used for trusted code in development. For production deployments handling untrusted code, use `LOGIC_FUNCTION_TYPE=LAMBDA` or `CODE_INTERPRETER_TYPE=E2B` (with sandboxing), or keep them disabled.</Warning>-### Available Drivers+### Logic Functions - Available Drivers| Driver | Environment Variable | Use Case | Security Level ||--------|---------------------|----------|----------------|-| Disabled | `SERVERLESS_TYPE=DISABLED` | Disable logic functions entirely | N/A |-| Local | `SERVERLESS_TYPE=LOCAL` | Development and trusted environments | Low (no sandboxing) |-| Lambda | `SERVERLESS_TYPE=LAMBDA` | Production with untrusted code | High (hardware-level isolation) |+| Disabled | `LOGIC_FUNCTION_TYPE=DISABLED` | Disable logic functions entirely | N/A |+| Local | `LOGIC_FUNCTION_TYPE=LOCAL` | Development and trusted environments | Low (no sandboxing) |+| Lambda | `LOGIC_FUNCTION_TYPE=LAMBDA` | Production with untrusted code | High (hardware-level isolation) |-### Recommended Configuration+### Logic Functions - Recommended Configuration**For development:**```bash-SERVERLESS_TYPE=LOCAL # default+LOGIC_FUNCTION_TYPE=LOCAL # default when NODE_ENV=development```**For production (AWS):**```bash-SERVERLESS_TYPE=LAMBDA-SERVERLESS_LAMBDA_REGION=us-east-1-SERVERLESS_LAMBDA_ROLE=arn:aws:iam::123456789:role/your-lambda-role-SERVERLESS_LAMBDA_ACCESS_KEY_ID=your-access-key-SERVERLESS_LAMBDA_SECRET_ACCESS_KEY=your-secret-key+LOGIC_FUNCTION_TYPE=LAMBDA+LOGIC_FUNCTION_LAMBDA_REGION=us-east-1+LOGIC_FUNCTION_LAMBDA_ROLE=arn:aws:iam::123456789:role/your-lambda-role+LOGIC_FUNCTION_LAMBDA_ACCESS_KEY_ID=your-access-key+LOGIC_FUNCTION_LAMBDA_SECRET_ACCESS_KEY=your-secret-key```**To disable logic functions:**```bash-SERVERLESS_TYPE=DISABLED+LOGIC_FUNCTION_TYPE=DISABLED # default when NODE_ENV=production```+### Code Interpreter - Available Drivers++| Driver | Environment Variable | Use Case | Security Level |+|--------|---------------------|----------|----------------|+| Disabled | `CODE_INTERPRETER_TYPE=DISABLED` | Disable AI code execution | N/A |+| Local | `CODE_INTERPRETER_TYPE=LOCAL` | Development only | Low (no sandboxing) |+| E2B | `CODE_INTERPRETER_TYPE=E_2_B` | Production with sandboxed execution | High (isolated sandbox) |+<Note>-When using `SERVERLESS_TYPE=DISABLED`, any attempt to execute a logic function will return an error. This is useful if you want to run Twenty without logic function capabilities.+When using `LOGIC_FUNCTION_TYPE=DISABLED` or `CODE_INTERPRETER_TYPE=DISABLED`, any attempt to execute will return an error. This is useful if you want to run Twenty without these capabilities.</Note>diff --git a/packages/twenty-server/.env.example b/packages/twenty-server/.env.exampleindex 345c6582858..98198786b60 100644--- a/packages/twenty-server/.env.example+++ b/packages/twenty-server/.env.example@@ -4,7 +4,6 @@ PG_DATABASE_URL=postgres://postgres:postgres@localhost:5432/defaultREDIS_URL=redis://localhost:6379APP_SECRET=replace_me_with_a_random_stringSIGN_IN_PREFILLED=true-CODE_INTERPRETER_TYPE=localIS_WORKSPACE_CREATION_LIMITED_TO_SERVER_ADMINS=falseFRONTEND_URL=http://localhost:3001@@ -34,8 +33,9 @@ FRONTEND_URL=http://localhost:3001# AUTH_GOOGLE_CLIENT_SECRET=replace_me_with_google_client_secret# AUTH_GOOGLE_CALLBACK_URL=http://localhost:3000/auth/google/redirect# AUTH_GOOGLE_APIS_CALLBACK_URL=http://localhost:3000/auth/google-apis/get-access-token-# SERVERLESS_TYPE=local-# SERVERLESS_LOGS_ENABLED=true+# CODE_INTERPRETER_TYPE=LOCAL+# LOGIC_FUNCTION_TYPE=LOCAL+# LOGIC_FUNCTION_LOGS_ENABLED=true# STORAGE_TYPE=local# STORAGE_LOCAL_PATH=.local-storage# SUPPORT_DRIVER=frontdiff --git a/packages/twenty-server/.env.test b/packages/twenty-server/.env.testindex e430b663297..6fdd1e8837a 100644--- a/packages/twenty-server/.env.test+++ b/packages/twenty-server/.env.test@@ -30,3 +30,5 @@ AUTH_MICROSOFT_APIS_CALLBACK_URL=http://localhost:3000/auth/microsoft-apis/get-aCLICKHOUSE_URL=http://default:clickhousePassword@localhost:8123/twentyIS_WORKSPACE_CREATION_V2_ENABLED=trueSHOULD_SEED_STANDARD_RECORD_PAGE_LAYOUTS=true++LOGIC_FUNCTION_TYPE=LOCALdiff --git a/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts b/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.tsindex 9f64e1f8069..24508d07987 100644--- a/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts+++ b/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts@@ -479,7 +479,10 @@ export class ConfigVariables {})@IsOptional()@CastToUpperSnakeCase()- LOGIC_FUNCTION_TYPE: LogicFunctionDriverType = LogicFunctionDriverType.LOCAL;+ LOGIC_FUNCTION_TYPE: LogicFunctionDriverType =+ process.env.NODE_ENV === NodeEnvironment.DEVELOPMENT+ ? LogicFunctionDriverType.LOCAL+ : LogicFunctionDriverType.DISABLED;@ConfigVariablesMetadata({group: ConfigVariablesGroup.LOGIC_FUNCTION_CONFIG,@@ -598,7 +601,9 @@ export class ConfigVariables {@IsOptional()@CastToUpperSnakeCase()CODE_INTERPRETER_TYPE: CodeInterpreterDriverType =- CodeInterpreterDriverType.DISABLED;+ process.env.NODE_ENV === NodeEnvironment.DEVELOPMENT+ ? CodeInterpreterDriverType.LOCAL+ : CodeInterpreterDriverType.DISABLED;@ConfigVariablesMetadata({group: ConfigVariablesGroup.CODE_INTERPRETER_CONFIG,