You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Serverless code interpreter sessions in Azure Container Apps
16
16
17
-
Azure Container Apps [dynamic sessions](sessions.md)provides fast and scalable access to a code interpreter. Each code interpreter session is fully isolated by a Hyper-V boundary and is designed to run untrusted code.
17
+
Azure Container Apps [dynamic sessions](sessions.md)provide fast and scalable access to a code interpreter. Each code interpreter session is fully isolated by a Hyper-V boundary and is designed to run untrusted code.
18
18
19
19
## Uses for code interpreter sessions
20
20
21
-
Code interpreter sessions are ideal for scenarios where you need to run code that is potentially malicious or could cause harm to the host system or other users, such as:
21
+
Code interpreter sessions are ideal for scenarios where you need to run code that's potentially malicious or could cause harm to the host system or other users, such as:
22
22
23
23
- Code generated by a large language model (LLM).
24
24
- Code submitted by an end user in a web or SaaS application.
25
25
26
-
For popular LLM frameworks such as LangChain, LlamaIndex, or Semantic Kernel, you can use [tools and plugins](#llm-framework-integrations) to integrate AI apps with code interpreter sessions.
26
+
For popular LLM frameworks such as LangChain, LlamaIndex, and Semantic Kernel, you can use [tools and plugins](#llm-framework-integrations) to integrate AI apps with code interpreter sessions.
27
27
28
-
Your applications can also integrate with code interpreter session using a [REST API](#management-api-endpoints). The API allows you to:
28
+
Your applications can also integrate with code interpreter session by using a [REST API](#management-api-endpoints). The API enables you to:
29
29
30
-
-Execute code in a session and retrieve results
30
+
-Run code in a session and retrieve results.
31
31
- Upload and download files to and from the session.
32
32
33
-
You can upload and download executable code files, or data files that your code can process.
33
+
You can upload and download executable code files or data files that your code can process.
34
34
35
-
The built-in code interpreter sessions support the most common code execution scenarios without the need to manage infrastructure or containers.
35
+
The built-in code interpreter sessions support the most common code execution scenarios without requiring you to manage infrastructure or containers.
36
36
37
37
If you need full control over the code execution environment or have a different scenario that requires isolated sandboxes, you can use [custom code interpreter sessions](sessions-custom-container.md).
38
38
39
39
## Code interpreter session pool
40
40
41
41
To use code interpreter sessions, you need an Azure resource called a [session pool](session-pool.md) that defines the configuration for code interpreter sessions.
42
42
43
-
In the session pool, you can specify settings such as the maximum number of concurrent sessions and how long a session can be idle before the session is terminated.
43
+
In the session pool, you can specify settings such as the maximum number of concurrent sessions and how long a session can be idle before the session is stopped.
44
44
45
-
You can create a session pool using the Azure portal, Azure CLI, or Azure Resource Manager templates. After you create a session pool, you can use the pool's management API endpoints to manage and execute code inside a session.
45
+
You can create a session pool by using the Azure portal, the Azure CLI, or Azure Resource Manager templates. After you create a session pool, you can use the pool's management API endpoints to manage and run code inside a session.
46
46
47
47
For more information about how to create and configure a session pool, see [Use session pools](./session-pool.md).
48
48
49
49
## Code execution in a session
50
50
51
-
After you create a session pool, your application can interact with sessions in the pool using an integration with an [LLM framework](#llm-framework-integrations) or by using the pool's [management API endpoints](#management-api-endpoints) directly.
51
+
After you create a session pool, your application can interact with sessions in the pool by using an integration with an [LLM framework](#llm-framework-integrations) or by using the pool's [management API endpoints](#management-api-endpoints) directly.
52
52
53
53
## Session identifiers
54
54
55
55
> [!IMPORTANT]
56
-
> The session identifier is sensitive information which requires you to use a secure process to manage its value. Part of this process requires that your application ensures each user or tenant only has access to their own sessions.
56
+
> The session identifier is sensitive information. You need to use a secure process to manage its value. Part of this process is to make sure that your application ensures each user or tenant only has access to their own sessions.
57
57
>
58
58
> Failure to secure access to sessions could result in misuse or unauthorized access to data stored in your users' sessions. For more information, see [Session identifiers](sessions-usage.md#identifiers).
59
59
60
-
When you interact with sessions in a pool, you use a [session identifier](sessions-usage.md#identifiers) to reference each session A session identifier is a string that you define that is unique within the session pool. If you're building a web application, you can use the user's ID. If you're building a chatbot, you can use the conversation ID.
60
+
When you interact with sessions in a pool, you use a [session identifier](sessions-usage.md#identifiers) to reference each session. A session identifier is a string that you define that's unique within the session pool. If you're building a web application, you can use the user's ID. If you're building a chatbot, you can use the conversation ID.
61
61
62
62
If there's a running session with the identifier, the session is reused. If there's no running session with the identifier, a new session is automatically created.
63
63
64
64
## Authentication
65
65
66
-
Authentication is handled using Microsoft Entra tokens. Valid Microsoft Entra tokens are generated by an identity belonging to the *Azure ContainerApps Session Executor* and *Contributor* roles on the session pool.
66
+
Authentication is handled via Microsoft Entra tokens. Valid Microsoft Entra tokens are generated by an identity belonging to the *Azure ContainerApps Session Executor* and *Contributor* roles on the session pool.
67
67
68
-
If you're using an LLM framework integration, the framework handles the token generation and management for you. Ensure that the application is configured with a managed identity with the necessary role assignments on the session pool.
68
+
If you're using an LLM framework integration, the framework handles the token generation and management for you. Ensure that the application is configured with a managed identity that has the necessary role assignments on the session pool.
69
69
70
-
If you're using the pool's management API endpoints directly, you must generate a token and include it in the `Authorization` header of your HTTP requests. In addition to the role assignments previously mentioned, token needs to contain an audience (`aud`) claim with the value `https://dynamicsessions.io`.
70
+
If you're using the pool's management API endpoints directly, you must generate a token and include it in the `Authorization` header of your HTTP requests. In addition to the role assignments previously mentioned, token needs to contain an audience (`aud`) claim that has the value `https://dynamicsessions.io`.
71
71
72
-
To learn more, see [Authentication and authorization](sessions-usage.md#authentication).
72
+
For more information, see [Authentication and authorization](sessions-usage.md#authentication).
73
73
74
74
## Work with files
75
75
76
76
You can upload and download files, and list all the files in a code interpreter session.
77
77
78
78
### Supported characters
79
79
80
-
Filenames and path must use only the following supported characters:
80
+
File names and paths must use only the following supported characters:
- Unicode characters: Includes Chinese, Japanese, and other international characters.
87
86
88
87
### Upload a file
89
88
90
-
To upload a file to a session, send a `POST` request to the `uploadFile` endpoint in a multipart form data request. Include the file data in the request body. The file must include a filename.
89
+
To upload a file to a session, send a `POST` request to the `uploadFile` endpoint in a multipart form data request. Include the file data in the request body. The file must include a file name.
91
90
92
-
Uploaded files are stored in the session's file system under the `/mnt/data` directory.
91
+
Uploaded files are stored in the session's file system in the `/mnt/data` directory.
93
92
94
93
The following example shows how to upload a file to a session.
95
94
96
-
Before you send the request, replace the placeholders between the `<>` brackets with values specific to your request.
95
+
Before you send the request, replace the placeholders between the `<>` brackets with values that are specific to your request.
97
96
98
97
```http
99
98
POST https://<REGION>.dynamicsessions.io/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/sessionPools/<SESSION_POOL_NAME>/files/upload?api-version=2024-02-02-preview&identifier=<SESSION_ID>
@@ -114,29 +113,29 @@ To download a file from a session's `/mnt/data` directory, send a `GET` request
114
113
115
114
The following example demonstrates how to format a `GET` request to download a file.
116
115
117
-
Before you send the request, replace the placeholders between the `<>` brackets with values specific to your request.
116
+
Before you send the request, replace the placeholders between the `<>` brackets with values that are specific to your request.
118
117
119
118
```http
120
119
GET https://<REGION>.dynamicsessions.io/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/sessionPools/<SESSION_POOL_NAME>/files/content/<FILE_NAME_AND_EXTENSION>?api-version=2024-02-02-preview&identifier=<SESSION_ID>
121
120
Authorization: Bearer <TOKEN>
122
121
```
123
122
124
-
### List the files
123
+
### List files
125
124
126
125
To list the files in a session's `/mnt/data` directory, send a `GET` request to the `files` endpoint.
127
126
128
-
The following example shows you how to list the files in a session's directory.
127
+
The following example shows how to list the files in a session's directory.
129
128
130
-
Before you send the request, replace the placeholders between the `<>` brackets with values specific to your request.
129
+
Before you send the request, replace the placeholders between the `<>` brackets with values that are specific to your request.
131
130
132
131
```http
133
132
GET https://<REGION>.dynamicsessions.io/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/sessionPools/<SESSION_POOL_NAME>/files?api-version=2024-02-02-preview&identifier=<SESSION_ID>
134
133
Authorization: Bearer <TOKEN>
135
134
```
136
135
137
-
The response contains a list of files in the session.
136
+
The response contains a list of the files in the session.
138
137
139
-
The following listing shows a sample of the type of response you can expect from requesting session contents.
138
+
The following listing shows a sample of the type of response you can expect when you request session contents.
140
139
141
140
```json
142
141
{
@@ -166,11 +165,11 @@ The following listing shows a sample of the type of response you can expect from
166
165
167
166
## Security
168
167
169
-
Code interpreter sessions are designed to run untrusted code in isolated environments, ensuring that your applications and data remain protected.
168
+
Code interpreter sessions are designed to run untrusted code in isolated environments to ensure that your applications and data remain protected.
170
169
171
170
## LLM framework integrations
172
171
173
-
Instead of using the session pool management API directly, the following LLM frameworksprovide integrations with code interpreter sessions:
172
+
Instead of using the session pool management API directly, you can use the following LLM frameworks, which provide integrations with code interpreter sessions.
174
173
175
174
| Framework | Package | Tutorial |
176
175
|-----------|---------|------------|
@@ -180,11 +179,11 @@ Instead of using the session pool management API directly, the following LLM fra
180
179
181
180
## Management API endpoints
182
181
183
-
If you're not using an LLM framework integration, you can interact with the session pool directly using the [management API endpoints](session-pool.md#management-endpoint).
182
+
If you're not using an LLM framework integration, you can interact with the session pool directly by using the [management API endpoints](session-pool.md#management-endpoint).
184
183
185
-
## Execute code in a session
184
+
## Run code in a session
186
185
187
-
To execute code in a session, send a `POST` request to the `code/execute` endpoint with the code to run in the request body. Each code execution is limited to a maximum runtime of 220 seconds.
186
+
To run code in a session, send a `POST` request to the `code/execute` endpoint with the code to run in the request body. Each code execution is limited to a maximum runtime of 220 seconds.
188
187
189
188
The following example prints `Hello, world!` in Python.
190
189
@@ -193,7 +192,7 @@ Before you send the request, replace the placeholders between the `<>` brackets
193
192
```http
194
193
POST https://<REGION>.dynamicsessions.io/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/sessionPools/<SESSION_POOL_NAME>/code/execute?api-version=2024-02-02-preview&identifier=<SESSION_ID>
195
194
Content-Type: application/json
196
-
Authorization: Bearer <token>
195
+
Authorization: Bearer <TOKEN>
197
196
198
197
{
199
198
"properties": {
@@ -208,16 +207,16 @@ To reuse a session, specify the same session identifier in subsequent requests.
208
207
209
208
#### Upload a file to a session
210
209
211
-
To upload a file to a session, send a `POST` request to the `uploadFile` endpoint in a multipart form data request. Include the file data in the request body. The file must include a filename.
210
+
To upload a file to a session, send a `POST` request to the `uploadFile` endpoint in a multipart form data request. Include the file data in the request body. The file must include a file name.
212
211
213
-
Uploaded files are stored in the session's file system under the `/mnt/data` directory.
212
+
Uploaded files are stored in the session's file system in the `/mnt/data` directory.
214
213
215
-
Before you send the request, replace the placeholders between the `<>` brackets with values specific to your request.
214
+
Before you send the request, replace the placeholders between the `<>` brackets with values that are specific to your request.
216
215
217
216
```http
218
217
POST https://<REGION>.dynamicsessions.io/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/sessionPools/<SESSION_POOL_NAME>/files/upload?api-version=2024-02-02-preview&identifier=<SESSION_ID>
> The file upload limit is `128MB`. If this is exceeded a `HTTP 413` may be returned.
230
+
> The file upload limit is 128 MB. If this limit is exceeded, you might get an HTTP 413 error.
232
231
233
232
#### Download a file from a session
234
233
235
234
To download a file from a session's `/mnt/data` directory, send a `GET` request to the `file/content/{filename}` endpoint. The response includes the file data.
236
235
237
-
Before you send the request, replace the placeholders between the `<>` brackets with values specific to your request.
236
+
Before you send the request, replace the placeholders between the `<>` brackets with values that are specific to your request.
238
237
239
238
```http
240
239
GET https://<REGION>.dynamicsessions.io/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/sessionPools/<SESSION_POOL_NAME>/files/content/<FILE_NAME_AND_EXTENSION>?api-version=2024-02-02-preview&identifier=<SESSION_ID>
@@ -245,7 +244,7 @@ Authorization: Bearer <TOKEN>
245
244
246
245
To list the files in a session's `/mnt/data` directory, send a `GET` request to the `files` endpoint.
247
246
248
-
Before you send the request, replace the placeholders between the `<>` brackets with values specific to your request.
247
+
Before you send the request, replace the placeholders between the `<>` brackets with values that are specific to your request.
249
248
250
249
```http
251
250
GET https://<REGION>.dynamicsessions.io/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/sessionPools/<SESSION_POOL_NAME>/files?api-version=2024-02-02-preview&identifier=<SESSION_ID>
@@ -254,7 +253,7 @@ Authorization: Bearer <TOKEN>
254
253
255
254
The response contains a list of files in the session.
256
255
257
-
The following listing shows a sample of the type of response you can expect from requesting session contents.
256
+
Following is an example of the type of response you can expect when you request session contents.
258
257
259
258
```json
260
259
{
@@ -284,11 +283,11 @@ The following listing shows a sample of the type of response you can expect from
284
283
285
284
## Preinstalled packages
286
285
287
-
Python code interpreter sessions include popular Python packages such as *NumPy*, *pandas*, and *scikit-learn*.
286
+
Python code interpreter sessions include popular Python packages such as NumPy, pandas, and scikit-learn.
288
287
289
288
To output the list of preinstalled packages, call the `code/execute` endpoint with the following code.
290
289
291
-
Before you send the request, replace the placeholders between the `<>` brackets with values specific to your request.
290
+
Before you send the request, replace the placeholders between the `<>` brackets with values that are specific to your request.
292
291
293
292
```http
294
293
POST https://<REGION>.dynamicsessions.io/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/sessionPools/<SESSION_POOL_NAME>/identifier/<SESSION_ID>/code/execute?api-version=2024-02-02-preview&identifier=<SESSION_ID>
Code interpreter sessions don't support logging directly. Your application that's interacting with the sessions can log requests to the session pool management API and its responses.
308
+
Code interpreter sessions don't support logging directly. The application that's interacting with the sessions can log requests to the session pool management API and its responses.
310
309
311
310
## Billing
312
311
313
312
Code interpreter sessions are billed based on the duration of each session. For more information, see [Billing](billing.md#dynamic-sessions).
314
313
315
-
## Next steps
314
+
## Next step
316
315
317
316
> [!div class="nextstepaction"]
318
317
> [Use code interpreter sessions with LangChain](./sessions-tutorial-langchain.md)
0 commit comments