aws-cdk.aws-bedrock-agentcore-alpha 2.221.0a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of aws-cdk.aws-bedrock-agentcore-alpha might be problematic. Click here for more details.

@@ -0,0 +1,810 @@
1
+ Metadata-Version: 2.1
2
+ Name: aws-cdk.aws-bedrock-agentcore-alpha
3
+ Version: 2.221.0a0
4
+ Summary: The CDK Construct Library for Amazon Bedrock
5
+ Home-page: https://github.com/aws/aws-cdk
6
+ Author: Amazon Web Services
7
+ License: Apache-2.0
8
+ Project-URL: Source, https://github.com/aws/aws-cdk.git
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: JavaScript
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Typing :: Typed
17
+ Classifier: Development Status :: 4 - Beta
18
+ Classifier: License :: OSI Approved
19
+ Classifier: Framework :: AWS CDK
20
+ Classifier: Framework :: AWS CDK :: 2
21
+ Requires-Python: ~=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ License-File: NOTICE
25
+ Requires-Dist: aws-cdk-lib <3.0.0,>=2.221.0
26
+ Requires-Dist: constructs <11.0.0,>=10.0.0
27
+ Requires-Dist: jsii <2.0.0,>=1.116.0
28
+ Requires-Dist: publication >=0.0.3
29
+ Requires-Dist: typeguard <4.3.0,>=2.13.3
30
+
31
+ # Amazon Bedrock AgentCore Construct Library
32
+
33
+ <!--BEGIN STABILITY BANNER-->---
34
+
35
+
36
+ ![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge)
37
+
38
+ > The APIs of higher level constructs in this module are experimental and under active development.
39
+ > They are subject to non-backward compatible changes or removal in any future version. These are
40
+ > not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be
41
+ > announced in the release notes. This means that while you may use them, you may need to update
42
+ > your source code when upgrading to a newer version of this package.
43
+
44
+ ---
45
+ <!--END STABILITY BANNER-->
46
+
47
+ | **Language** | **Package** |
48
+ | :--------------------------------------------------------------------------------------------- | --------------------------------------- |
49
+ | ![Typescript Logo](https://docs.aws.amazon.com/cdk/api/latest/img/typescript32.png) TypeScript | `@aws-cdk/aws-bedrock-agentcore-alpha` |
50
+
51
+ [Amazon Bedrock AgentCore](https://aws.amazon.com/bedrock/agentcore/) enables you to deploy and operate highly capable AI agents securely, at scale. It offers infrastructure purpose-built for dynamic agent workloads, powerful tools to enhance agents, and essential controls for real-world deployment. AgentCore services can be used together or independently and work with any framework including CrewAI, LangGraph, LlamaIndex, and Strands Agents, as well as any foundation model in or outside of Amazon Bedrock, giving you ultimate flexibility. AgentCore eliminates the undifferentiated heavy lifting of building specialized agent infrastructure, so you can accelerate agents to production.
52
+
53
+ This construct library facilitates the deployment of Bedrock AgentCore primitives, enabling you to create sophisticated AI applications that can interact with your systems and data sources.
54
+
55
+ ## Table of contents
56
+
57
+ * [AgentCore Runtime](#agentcore-runtime)
58
+
59
+ * [Runtime Versioning](#runtime-versioning)
60
+ * [Runtime Endpoints](#runtime-endpoints)
61
+ * [AgentCore Runtime Properties](#agentcore-runtime-properties)
62
+ * [Runtime Endpoint Properties](#runtime-endpoint-properties)
63
+ * [Creating a Runtime](#creating-a-runtime)
64
+
65
+ * [Option 1: Use an existing image in ECR](#option-1-use-an-existing-image-in-ecr)
66
+ * [Managing Endpoints and Versions](#managing-endpoints-and-versions)
67
+ * [Option 2: Use a local asset](#option-2-use-a-local-asset)
68
+ * [Browser Custom tool](#browser)
69
+
70
+ * [Browser properties](#browser-properties)
71
+ * [Browser Network modes](#browser-network-modes)
72
+ * [Basic Browser Creation](#basic-browser-creation)
73
+ * [Browser IAM permissions](#browser-iam-permissions)
74
+ * [Code Interpreter Custom tool](#code-interpreter)
75
+
76
+ * [Code Interpreter properties](#code-interpreter-properties)
77
+ * [Code Interpreter Network Modes](#code-interpreter-network-modes)
78
+ * [Basic Code Interpreter Creation](#basic-code-interpreter-creation)
79
+ * [Code Interpreter IAM permissions](#code-interpreter-iam-permissions)
80
+
81
+ ## AgentCore Runtime
82
+
83
+ The AgentCore Runtime construct enables you to deploy containerized agents on Amazon Bedrock AgentCore.
84
+ This L2 construct simplifies runtime creation just pass your ECR repository name
85
+ and the construct handles all the configuration with sensible defaults.
86
+
87
+ ### Runtime Endpoints
88
+
89
+ Endpoints provide a stable way to invoke specific versions of your agent runtime, enabling controlled deployments across different environments.
90
+ When you create an agent runtime, Amazon Bedrock AgentCore automatically creates a "DEFAULT" endpoint which always points to the latest version
91
+ of runtime.
92
+
93
+ You can create additional endpoints in two ways:
94
+
95
+ 1. **Using Runtime.addEndpoint()** - Convenient method when creating endpoints alongside the runtime.
96
+ 2. **Using RuntimeEndpoint** - Flexible approach for existing runtimes.
97
+
98
+ For example, you might keep a "production" endpoint on a stable version while testing newer versions
99
+ through a "staging" endpoint. This separation allows you to test changes thoroughly before promoting them
100
+ to production by simply updating the endpoint to point to the newer version.
101
+
102
+ ### AgentCore Runtime Properties
103
+
104
+ | Name | Type | Required | Description |
105
+ |------|------|----------|-------------|
106
+ | `runtimeName` | `string` | Yes | The name of the agent runtime. Valid characters are a-z, A-Z, 0-9, _ (underscore). Must start with a letter and can be up to 48 characters long |
107
+ | `agentRuntimeArtifact` | `AgentRuntimeArtifact` | Yes | The artifact configuration for the agent runtime containing the container configuration with ECR URI |
108
+ | `executionRole` | `iam.IRole` | No | The IAM role that provides permissions for the agent runtime. If not provided, a role will be created automatically |
109
+ | `networkConfiguration` | `NetworkConfiguration` | No | Network configuration for the agent runtime. Defaults to `RuntimeNetworkConfiguration.usingPublicNetwork()` |
110
+ | `description` | `string` | No | Optional description for the agent runtime |
111
+ | `protocolConfiguration` | `ProtocolType` | No | Protocol configuration for the agent runtime. Defaults to `ProtocolType.HTTP` |
112
+ | `authorizerConfiguration` | `RuntimeAuthorizerConfiguration` | No | Authorizer configuration for the agent runtime. Use `RuntimeAuthorizerConfiguration` static methods to create configurations for IAM, Cognito, JWT, or OAuth authentication |
113
+ | `environmentVariables` | `{ [key: string]: string }` | No | Environment variables for the agent runtime. Maximum 50 environment variables |
114
+ | `tags` | `{ [key: string]: string }` | No | Tags for the agent runtime. A list of key:value pairs of tags to apply to this Runtime resource |
115
+
116
+ ### Runtime Endpoint Properties
117
+
118
+ | Name | Type | Required | Description |
119
+ |------|------|----------|-------------|
120
+ | `endpointName` | `string` | Yes | The name of the runtime endpoint. Valid characters are a-z, A-Z, 0-9, _ (underscore). Must start with a letter and can be up to 48 characters long |
121
+ | `agentRuntimeId` | `string` | Yes | The Agent Runtime ID for this endpoint |
122
+ | `agentRuntimeVersion` | `string` | Yes | The Agent Runtime version for this endpoint. Must be between 1 and 5 characters long.|
123
+ | `description` | `string` | No | Optional description for the runtime endpoint |
124
+ | `tags` | `{ [key: string]: string }` | No | Tags for the runtime endpoint |
125
+
126
+ ### Creating a Runtime
127
+
128
+ #### Option 1: Use an existing image in ECR
129
+
130
+ Reference an image available within ECR.
131
+
132
+ ```python
133
+ repository = ecr.Repository(self, "TestRepository",
134
+ repository_name="test-agent-runtime"
135
+ )
136
+
137
+ # The runtime by default create ECR permission only for the repository available in the account the stack is being deployed
138
+ agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")
139
+
140
+ # Create runtime using the built image
141
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
142
+ runtime_name="myAgent",
143
+ agent_runtime_artifact=agent_runtime_artifact
144
+ )
145
+ ```
146
+
147
+ To grant the runtime permission to invoke a Bedrock model or inference profile:
148
+
149
+ ```text
150
+ // Note: This example uses @aws-cdk/aws-bedrock-alpha which must be installed separately
151
+ import * as bedrock from '@aws-cdk/aws-bedrock-alpha';
152
+
153
+ // Create a cross-region inference profile for Claude 3.7 Sonnet
154
+ const inferenceProfile = bedrock.CrossRegionInferenceProfile.fromConfig({
155
+ geoRegion: bedrock.CrossRegionInferenceProfileRegion.US,
156
+ model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_7_SONNET_V1_0
157
+ });
158
+
159
+ // Grant the runtime permission to invoke the inference profile
160
+ inferenceProfile.grantInvoke(runtime);
161
+ ```
162
+
163
+ #### Option 2: Use a local asset
164
+
165
+ Reference a local directory containing a Dockerfile.
166
+ Images are built from a local Docker context directory (with a Dockerfile), uploaded to Amazon Elastic Container Registry (ECR)
167
+ by the CDK toolkit,and can be naturally referenced in your CDK app .
168
+
169
+ ```python
170
+ agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_asset(
171
+ path.join(__dirname, "path to agent dockerfile directory"))
172
+
173
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
174
+ runtime_name="myAgent",
175
+ agent_runtime_artifact=agent_runtime_artifact
176
+ )
177
+ ```
178
+
179
+ ### Runtime Versioning
180
+
181
+ Amazon Bedrock AgentCore automatically manages runtime versioning to ensure safe deployments and rollback capabilities.
182
+ When you create an agent runtime, AgentCore automatically creates version 1 (V1). Each subsequent update to the
183
+ runtime configuration (such as updating the container image, modifying network settings, or changing protocol configurations)
184
+ creates a new immutable version. These versions contain complete, self-contained configurations that can be referenced by endpoints,
185
+ allowing you to maintain different versions for different environments or gradually roll out updates.
186
+
187
+ #### Managing Endpoints and Versions
188
+
189
+ Amazon Bedrock AgentCore automatically manages runtime versioning to provide safe deployments and rollback capabilities. You can follow
190
+ the steps below to understand how to use versioning with runtime for controlled deployments across different environments.
191
+
192
+ ##### Step 1: Initial Deployment
193
+
194
+ When you first create an agent runtime, AgentCore automatically creates Version 1 of your runtime. At this point, a DEFAULT endpoint is
195
+ automatically created that points to Version 1. This DEFAULT endpoint serves as the main access point for your runtime.
196
+
197
+ ```python
198
+ repository = ecr.Repository(self, "TestRepository",
199
+ repository_name="test-agent-runtime"
200
+ )
201
+
202
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
203
+ runtime_name="myAgent",
204
+ agent_runtime_artifact=agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")
205
+ )
206
+ ```
207
+
208
+ ##### Step 2: Creating Custom Endpoints
209
+
210
+ After the initial deployment, you can create additional endpoints for different environments. For example, you might create a "production"
211
+ endpoint that explicitly points to Version 1. This allows you to maintain stable access points for specific environments while keeping the
212
+ flexibility to test newer versions elsewhere.
213
+
214
+ ```python
215
+ repository = ecr.Repository(self, "TestRepository",
216
+ repository_name="test-agent-runtime"
217
+ )
218
+
219
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
220
+ runtime_name="myAgent",
221
+ agent_runtime_artifact=agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")
222
+ )
223
+
224
+ prod_endpoint = runtime.add_endpoint("production",
225
+ version="1",
226
+ description="Stable production endpoint - pinned to v1"
227
+ )
228
+ ```
229
+
230
+ ##### Step 3: Runtime Update Deployment
231
+
232
+ When you update the runtime configuration (such as updating the container image, modifying network settings, or changing protocol
233
+ configurations), AgentCore automatically creates a new version (Version 2). Upon this update:
234
+
235
+ * Version 2 is created automatically with the new configuration
236
+ * The DEFAULT endpoint automatically updates to point to Version 2
237
+ * Any explicitly pinned endpoints (like the production endpoint) remain on their specified versions
238
+
239
+ ```python
240
+ repository = ecr.Repository(self, "TestRepository",
241
+ repository_name="test-agent-runtime"
242
+ )
243
+
244
+ agent_runtime_artifact_new = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v2.0.0")
245
+
246
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
247
+ runtime_name="myAgent",
248
+ agent_runtime_artifact=agent_runtime_artifact_new
249
+ )
250
+ ```
251
+
252
+ ##### Step 4: Testing with Staging Endpoints
253
+
254
+ Once Version 2 exists, you can create a staging endpoint that points to the new version. This staging endpoint allows you to test the
255
+ new version in a controlled environment before promoting it to production. This separation ensures that production traffic continues
256
+ to use the stable version while you validate the new version.
257
+
258
+ ```python
259
+ repository = ecr.Repository(self, "TestRepository",
260
+ repository_name="test-agent-runtime"
261
+ )
262
+
263
+ agent_runtime_artifact_new = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v2.0.0")
264
+
265
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
266
+ runtime_name="myAgent",
267
+ agent_runtime_artifact=agent_runtime_artifact_new
268
+ )
269
+
270
+ staging_endpoint = runtime.add_endpoint("staging",
271
+ version="2",
272
+ description="Staging environment for testing new version"
273
+ )
274
+ ```
275
+
276
+ ##### Step 5: Promoting to Production
277
+
278
+ After thoroughly testing the new version through the staging endpoint, you can update the production endpoint to point to Version 2.
279
+ This controlled promotion process ensures that you can validate changes before they affect production traffic.
280
+
281
+ ```python
282
+ repository = ecr.Repository(self, "TestRepository",
283
+ repository_name="test-agent-runtime"
284
+ )
285
+
286
+ agent_runtime_artifact_new = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v2.0.0")
287
+
288
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
289
+ runtime_name="myAgent",
290
+ agent_runtime_artifact=agent_runtime_artifact_new
291
+ )
292
+
293
+ prod_endpoint = runtime.add_endpoint("production",
294
+ version="2", # New version added here
295
+ description="Stable production endpoint"
296
+ )
297
+ ```
298
+
299
+ ### Creating Standalone Runtime Endpoints
300
+
301
+ RuntimeEndpoint can also be created as a standalone resource.
302
+
303
+ #### Example: Creating an endpoint for an existing runtime
304
+
305
+ ```python
306
+ # Reference an existing runtime by its ID
307
+ existing_runtime_id = "abc123-runtime-id" # The ID of an existing runtime
308
+
309
+ # Create a standalone endpoint
310
+ endpoint = agentcore.RuntimeEndpoint(self, "MyEndpoint",
311
+ endpoint_name="production",
312
+ agent_runtime_id=existing_runtime_id,
313
+ agent_runtime_version="1", # Specify which version to use
314
+ description="Production endpoint for existing runtime"
315
+ )
316
+ ```
317
+
318
+ ### Runtime Authentication Configuration
319
+
320
+ The AgentCore Runtime supports multiple authentication modes to secure access to your agent endpoints. Authentication is configured during runtime creation using the `RuntimeAuthorizerConfiguration` class's static factory methods.
321
+
322
+ #### IAM Authentication (Default)
323
+
324
+ IAM authentication is the default mode, when no authorizerConfiguration is set then the underlying service use IAM.
325
+
326
+ #### Cognito Authentication
327
+
328
+ To configure AWS Cognito User Pool authentication:
329
+
330
+ ```python
331
+ repository = ecr.Repository(self, "TestRepository",
332
+ repository_name="test-agent-runtime"
333
+ )
334
+ agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")
335
+
336
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
337
+ runtime_name="myAgent",
338
+ agent_runtime_artifact=agent_runtime_artifact,
339
+ authorizer_configuration=agentcore.RuntimeAuthorizerConfiguration.using_cognito("us-west-2_ABC123", "client123", "us-west-2")
340
+ )
341
+ ```
342
+
343
+ #### JWT Authentication
344
+
345
+ To configure custom JWT authentication with your own OpenID Connect (OIDC) provider:
346
+
347
+ ```python
348
+ repository = ecr.Repository(self, "TestRepository",
349
+ repository_name="test-agent-runtime"
350
+ )
351
+ agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")
352
+
353
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
354
+ runtime_name="myAgent",
355
+ agent_runtime_artifact=agent_runtime_artifact,
356
+ authorizer_configuration=agentcore.RuntimeAuthorizerConfiguration.using_jWT("https://example.com/.well-known/openid-configuration", ["client1", "client2"], ["audience1"])
357
+ )
358
+ ```
359
+
360
+ **Note**: The discovery URL must end with `/.well-known/openid-configuration`.
361
+
362
+ #### OAuth Authentication
363
+
364
+ To configure OAuth 2.0 authentication:
365
+
366
+ ```python
367
+ repository = ecr.Repository(self, "TestRepository",
368
+ repository_name="test-agent-runtime"
369
+ )
370
+ agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")
371
+
372
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
373
+ runtime_name="myAgent",
374
+ agent_runtime_artifact=agent_runtime_artifact,
375
+ authorizer_configuration=agentcore.RuntimeAuthorizerConfiguration.using_oAuth("https://github.com/.well-known/openid-configuration", "oauth_client_123")
376
+ )
377
+ ```
378
+
379
+ #### Using a Custom IAM Role
380
+
381
+ Instead of using the auto-created execution role, you can provide your own IAM role with specific permissions:
382
+ The auto-created role includes all necessary baseline permissions for ECR access, CloudWatch logging, and X-Ray tracing. When providing a custom role, ensure these permissions are included.
383
+
384
+ ### Runtime Network Configuration
385
+
386
+ The AgentCore Runtime supports two network modes for deployment:
387
+
388
+ #### Public Network Mode (Default)
389
+
390
+ By default, runtimes are deployed in PUBLIC network mode, which provides internet access suitable for less sensitive or open-use scenarios:
391
+
392
+ ```python
393
+ repository = ecr.Repository(self, "TestRepository",
394
+ repository_name="test-agent-runtime"
395
+ )
396
+ agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")
397
+
398
+ # Explicitly using public network (this is the default)
399
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
400
+ runtime_name="myAgent",
401
+ agent_runtime_artifact=agent_runtime_artifact,
402
+ network_configuration=agentcore.RuntimeNetworkConfiguration.using_public_network()
403
+ )
404
+ ```
405
+
406
+ #### VPC Network Mode
407
+
408
+ For enhanced security and network isolation, you can deploy your runtime within a VPC:
409
+
410
+ ```python
411
+ repository = ecr.Repository(self, "TestRepository",
412
+ repository_name="test-agent-runtime"
413
+ )
414
+ agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")
415
+
416
+ # Create or use an existing VPC
417
+ vpc = ec2.Vpc(self, "MyVpc",
418
+ max_azs=2
419
+ )
420
+
421
+ # Configure runtime with VPC
422
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
423
+ runtime_name="myAgent",
424
+ agent_runtime_artifact=agent_runtime_artifact,
425
+ network_configuration=agentcore.RuntimeNetworkConfiguration.using_vpc(self,
426
+ vpc=vpc,
427
+ vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS)
428
+ )
429
+ )
430
+ ```
431
+
432
+ #### Managing Security Groups with VPC Configuration
433
+
434
+ When using VPC mode, the Runtime implements `ec2.IConnectable`, allowing you to manage network access using the `connections` property:
435
+
436
+ ```python
437
+ vpc = ec2.Vpc(self, "MyVpc",
438
+ max_azs=2
439
+ )
440
+
441
+ repository = ecr.Repository(self, "TestRepository",
442
+ repository_name="test-agent-runtime"
443
+ )
444
+ agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_ecr_repository(repository, "v1.0.0")
445
+
446
+ # Create runtime with VPC configuration
447
+ runtime = agentcore.Runtime(self, "MyAgentRuntime",
448
+ runtime_name="myAgent",
449
+ agent_runtime_artifact=agent_runtime_artifact,
450
+ network_configuration=agentcore.RuntimeNetworkConfiguration.using_vpc(self,
451
+ vpc=vpc,
452
+ vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PRIVATE_WITH_EGRESS)
453
+ )
454
+ )
455
+
456
+ # Now you can manage network access using the connections property
457
+ # Allow inbound HTTPS traffic from a specific security group
458
+ web_server_security_group = ec2.SecurityGroup(self, "WebServerSG", vpc=vpc)
459
+ runtime.connections.allow_from(web_server_security_group, ec2.Port.tcp(443), "Allow HTTPS from web servers")
460
+
461
+ # Allow outbound connections to a database
462
+ database_security_group = ec2.SecurityGroup(self, "DatabaseSG", vpc=vpc)
463
+ runtime.connections.allow_to(database_security_group, ec2.Port.tcp(5432), "Allow PostgreSQL connection")
464
+
465
+ # Allow outbound HTTPS to anywhere (for external API calls)
466
+ runtime.connections.allow_to_any_ipv4(ec2.Port.tcp(443), "Allow HTTPS outbound")
467
+ ```
468
+
469
+ ## Browser
470
+
471
+ The Amazon Bedrock AgentCore Browser provides a secure, cloud-based browser that enables AI agents to interact with websites. It includes security features such as session isolation, built-in observability through live viewing, CloudTrail logging, and session replay capabilities.
472
+
473
+ Additional information about the browser tool can be found in the [official documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/browser-tool.html)
474
+
475
+ ### Browser Network modes
476
+
477
+ The Browser construct supports the following network modes:
478
+
479
+ 1. **Public Network Mode** (`BrowserNetworkMode.usingPublicNetwork()`) - Default
480
+
481
+ * Allows internet access for web browsing and external API calls
482
+ * Suitable for scenarios where agents need to interact with publicly available websites
483
+ * Enables full web browsing capabilities
484
+ * VPC mode is not supported with this option
485
+ 2. **VPC (Virtual Private Cloud)** (`BrowserNetworkMode.usingVpc()`)
486
+
487
+ * Select whether to run the browser in a virtual private cloud (VPC).
488
+ * By configuring VPC connectivity, you enable secure access to private resources such as databases, internal APIs, and services within your VPC.
489
+
490
+ While the VPC itself is mandatory, these are optional:
491
+
492
+ * Subnets - if not provided, CDK will select appropriate subnets from the VPC
493
+ * Security Groups - if not provided, CDK will create a default security group
494
+ * Specific subnet selection criteria - you can let CDK choose automatically
495
+
496
+ For more information on VPC connectivity for Amazon Bedrock AgentCore Browser, please refer to the [official documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/agentcore-vpc.html).
497
+
498
+ ### Browser Properties
499
+
500
+ | Name | Type | Required | Description |
501
+ |------|------|----------|-------------|
502
+ | `browserCustomName` | `string` | Yes | The name of the browser. Must start with a letter and can be up to 48 characters long. Pattern: `[a-zA-Z][a-zA-Z0-9_]{0,47}` |
503
+ | `description` | `string` | No | Optional description for the browser. Can have up to 200 characters |
504
+ | `networkConfiguration` | `BrowserNetworkConfiguration` | No | Network configuration for browser. Defaults to PUBLIC network mode |
505
+ | `recordingConfig` | `RecordingConfig` | No | Recording configuration for browser. Defaults to no recording |
506
+ | `executionRole` | `iam.IRole` | No | The IAM role that provides permissions for the browser to access AWS services. A new role will be created if not provided |
507
+ | `tags` | `{ [key: string]: string }` | No | Tags to apply to the browser resource |
508
+
509
+ ### Basic Browser Creation
510
+
511
+ ```python
512
+ # Create a basic browser with public network access
513
+ browser = agentcore.BrowserCustom(self, "MyBrowser",
514
+ browser_custom_name="my_browser",
515
+ description="A browser for web automation"
516
+ )
517
+ ```
518
+
519
+ ### Browser with Tags
520
+
521
+ ```python
522
+ # Create a browser with custom tags
523
+ browser = agentcore.BrowserCustom(self, "MyBrowser",
524
+ browser_custom_name="my_browser",
525
+ description="A browser for web automation with tags",
526
+ network_configuration=agentcore.BrowserNetworkConfiguration.using_public_network(),
527
+ tags={
528
+ "Environment": "Production",
529
+ "Team": "AI/ML",
530
+ "Project": "AgentCore"
531
+ }
532
+ )
533
+ ```
534
+
535
+ ### Browser with VPC
536
+
537
+ ```python
538
+ browser = agentcore.BrowserCustom(self, "BrowserVpcWithRecording",
539
+ browser_custom_name="browser_recording",
540
+ network_configuration=agentcore.BrowserNetworkConfiguration.using_vpc(self,
541
+ vpc=ec2.Vpc(self, "VPC", restrict_default_security_group=False)
542
+ )
543
+ )
544
+ ```
545
+
546
+ Browser exposes a [connections](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Connections.html) property. This property returns a connections object, which simplifies the process of defining and managing ingress and egress rules for security groups in your AWS CDK applications. Instead of directly manipulating security group rules, you interact with the Connections object of a construct, which then translates your connectivity requirements into the appropriate security group rules. For instance:
547
+
548
+ ```python
549
+ vpc = ec2.Vpc(self, "testVPC")
550
+
551
+ browser = agentcore.BrowserCustom(self, "test-browser",
552
+ browser_custom_name="test_browser",
553
+ network_configuration=agentcore.BrowserNetworkConfiguration.using_vpc(self,
554
+ vpc=vpc
555
+ )
556
+ )
557
+
558
+ browser.connections.add_security_group(ec2.SecurityGroup(self, "AdditionalGroup", vpc=vpc))
559
+ ```
560
+
561
+ So security groups can be added after the browser construct creation. You can use methods like allowFrom() and allowTo() to grant ingress access to/egress access from a specified peer over a given portRange. The Connections object automatically adds the necessary ingress or egress rules to the security group(s) associated with the calling construct.
562
+
563
+ ### Browser with Recording Configuration
564
+
565
+ ```python
566
+ # Create an S3 bucket for recordings
567
+ recording_bucket = s3.Bucket(self, "RecordingBucket",
568
+ bucket_name="my-browser-recordings",
569
+ removal_policy=RemovalPolicy.DESTROY
570
+ )
571
+
572
+ # Create browser with recording enabled
573
+ browser = agentcore.BrowserCustom(self, "MyBrowser",
574
+ browser_custom_name="my_browser",
575
+ description="Browser with recording enabled",
576
+ network_configuration=agentcore.BrowserNetworkConfiguration.using_public_network(),
577
+ recording_config=agentcore.RecordingConfig(
578
+ enabled=True,
579
+ s3_location=s3.Location(
580
+ bucket_name=recording_bucket.bucket_name,
581
+ object_key="browser-recordings/"
582
+ )
583
+ )
584
+ )
585
+ ```
586
+
587
+ ### Browser with Custom Execution Role
588
+
589
+ ```python
590
+ # Create a custom execution role
591
+ execution_role = iam.Role(self, "BrowserExecutionRole",
592
+ assumed_by=iam.ServicePrincipal("bedrock-agentcore.amazonaws.com"),
593
+ managed_policies=[
594
+ iam.ManagedPolicy.from_aws_managed_policy_name("AmazonBedrockAgentCoreBrowserExecutionRolePolicy")
595
+ ]
596
+ )
597
+
598
+ # Create browser with custom execution role
599
+ browser = agentcore.BrowserCustom(self, "MyBrowser",
600
+ browser_custom_name="my_browser",
601
+ description="Browser with custom execution role",
602
+ network_configuration=agentcore.BrowserNetworkConfiguration.using_public_network(),
603
+ execution_role=execution_role
604
+ )
605
+ ```
606
+
607
+ ### Browser with S3 Recording and Permissions
608
+
609
+ ```python
610
+ # Create an S3 bucket for recordings
611
+ recording_bucket = s3.Bucket(self, "RecordingBucket",
612
+ bucket_name="my-browser-recordings",
613
+ removal_policy=RemovalPolicy.DESTROY
614
+ )
615
+
616
+ # Create browser with recording enabled
617
+ browser = agentcore.BrowserCustom(self, "MyBrowser",
618
+ browser_custom_name="my_browser",
619
+ description="Browser with recording enabled",
620
+ network_configuration=agentcore.BrowserNetworkConfiguration.using_public_network(),
621
+ recording_config=agentcore.RecordingConfig(
622
+ enabled=True,
623
+ s3_location=s3.Location(
624
+ bucket_name=recording_bucket.bucket_name,
625
+ object_key="browser-recordings/"
626
+ )
627
+ )
628
+ )
629
+ ```
630
+
631
+ ### Browser IAM Permissions
632
+
633
+ The Browser construct provides convenient methods for granting IAM permissions:
634
+
635
+ ```python
636
+ # Create a browser
637
+ browser = agentcore.BrowserCustom(self, "MyBrowser",
638
+ browser_custom_name="my_browser",
639
+ description="Browser for web automation",
640
+ network_configuration=agentcore.BrowserNetworkConfiguration.using_public_network()
641
+ )
642
+
643
+ # Create a role that needs access to the browser
644
+ user_role = iam.Role(self, "UserRole",
645
+ assumed_by=iam.ServicePrincipal("lambda.amazonaws.com")
646
+ )
647
+
648
+ # Grant read permissions (Get and List actions)
649
+ browser.grant_read(user_role)
650
+
651
+ # Grant use permissions (Start, Update, Stop actions)
652
+ browser.grant_use(user_role)
653
+
654
+ # Grant specific custom permissions
655
+ browser.grant(user_role, "bedrock-agentcore:GetBrowserSession")
656
+ ```
657
+
658
+ ## Code Interpreter
659
+
660
+ The Amazon Bedrock AgentCore Code Interpreter enables AI agents to write and execute code securely in sandbox environments, enhancing their accuracy and expanding their ability to solve complex end-to-end tasks. This is critical in Agentic AI applications where the agents may execute arbitrary code that can lead to data compromise or security risks. The AgentCore Code Interpreter tool provides secure code execution, which helps you avoid running into these issues.
661
+
662
+ For more information about code interpreter, please refer to the [official documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-tool.html)
663
+
664
+ ### Code Interpreter Network Modes
665
+
666
+ The Code Interpreter construct supports the following network modes:
667
+
668
+ 1. **Public Network Mode** (`CodeInterpreterNetworkMode.usingPublicNetwork()`) - Default
669
+
670
+ * Allows internet access for package installation and external API calls
671
+ * Suitable for development and testing environments
672
+ * Enables downloading Python packages from PyPI
673
+ 2. **Sandbox Network Mode** (`CodeInterpreterNetworkMode.usingSandboxNetwork()`)
674
+
675
+ * Isolated network environment with no internet access
676
+ * Suitable for production environments with strict security requirements
677
+ * Only allows access to pre-installed packages and local resources
678
+ 3. **VPC (Virtual Private Cloud)** (`CodeInterpreterNetworkMode.usingVpc()`)
679
+
680
+ * Select whether to run the browser in a virtual private cloud (VPC).
681
+ * By configuring VPC connectivity, you enable secure access to private resources such as databases, internal APIs, and services within your VPC.
682
+
683
+ While the VPC itself is mandatory, these are optional:
684
+
685
+ * Subnets - if not provided, CDK will select appropriate subnets from the VPC
686
+ * Security Groups - if not provided, CDK will create a default security group
687
+ * Specific subnet selection criteria - you can let CDK choose automatically
688
+
689
+ For more information on VPC connectivity for Amazon Bedrock AgentCore Browser, please refer to the [official documentation](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/agentcore-vpc.html).
690
+
691
+ ### Code Interpreter Properties
692
+
693
+ | Name | Type | Required | Description |
694
+ |------|------|----------|-------------|
695
+ | `codeInterpreterCustomName` | `string` | Yes | The name of the code interpreter. Must start with a letter and can be up to 48 characters long. Pattern: `[a-zA-Z][a-zA-Z0-9_]{0,47}` |
696
+ | `description` | `string` | No | Optional description for the code interpreter. Can have up to 200 characters |
697
+ | `executionRole` | `iam.IRole` | No | The IAM role that provides permissions for the code interpreter to access AWS services. A new role will be created if not provided |
698
+ | `networkConfiguration` | `CodeInterpreterNetworkConfiguration` | No | Network configuration for code interpreter. Defaults to PUBLIC network mode |
699
+ | `tags` | `{ [key: string]: string }` | No | Tags to apply to the code interpreter resource |
700
+
701
+ ### Basic Code Interpreter Creation
702
+
703
+ ```python
704
+ # Create a basic code interpreter with public network access
705
+ code_interpreter = agentcore.CodeInterpreterCustom(self, "MyCodeInterpreter",
706
+ code_interpreter_custom_name="my_code_interpreter",
707
+ description="A code interpreter for Python execution"
708
+ )
709
+ ```
710
+
711
+ ### Code Interpreter with VPC
712
+
713
+ ```python
714
+ code_interpreter = agentcore.CodeInterpreterCustom(self, "MyCodeInterpreter",
715
+ code_interpreter_custom_name="my_sandbox_interpreter",
716
+ description="Code interpreter with isolated network access",
717
+ network_configuration=agentcore.BrowserNetworkConfiguration.using_vpc(self,
718
+ vpc=ec2.Vpc(self, "VPC", restrict_default_security_group=False)
719
+ )
720
+ )
721
+ ```
722
+
723
+ Code Interpreter exposes a [connections](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Connections.html) property. This property returns a connections object, which simplifies the process of defining and managing ingress and egress rules for security groups in your AWS CDK applications. Instead of directly manipulating security group rules, you interact with the Connections object of a construct, which then translates your connectivity requirements into the appropriate security group rules. For instance:
724
+
725
+ ```python
726
+ vpc = ec2.Vpc(self, "testVPC")
727
+
728
+ code_interpreter = agentcore.CodeInterpreterCustom(self, "MyCodeInterpreter",
729
+ code_interpreter_custom_name="my_sandbox_interpreter",
730
+ description="Code interpreter with isolated network access",
731
+ network_configuration=agentcore.BrowserNetworkConfiguration.using_vpc(self,
732
+ vpc=vpc
733
+ )
734
+ )
735
+
736
+ code_interpreter.connections.add_security_group(ec2.SecurityGroup(self, "AdditionalGroup", vpc=vpc))
737
+ ```
738
+
739
+ So security groups can be added after the browser construct creation. You can use methods like allowFrom() and allowTo() to grant ingress access to/egress access from a specified peer over a given portRange. The Connections object automatically adds the necessary ingress or egress rules to the security group(s) associated with the calling construct.
740
+
741
+ ### Code Interpreter with Sandbox Network Mode
742
+
743
+ ```python
744
+ # Create code interpreter with sandbox network mode (isolated)
745
+ code_interpreter = agentcore.CodeInterpreterCustom(self, "MyCodeInterpreter",
746
+ code_interpreter_custom_name="my_sandbox_interpreter",
747
+ description="Code interpreter with isolated network access",
748
+ network_configuration=agentcore.CodeInterpreterNetworkConfiguration.using_sandbox_network()
749
+ )
750
+ ```
751
+
752
+ ### Code Interpreter with Custom Execution Role
753
+
754
+ ```python
755
+ # Create a custom execution role
756
+ execution_role = iam.Role(self, "CodeInterpreterExecutionRole",
757
+ assumed_by=iam.ServicePrincipal("bedrock-agentcore.amazonaws.com")
758
+ )
759
+
760
+ # Create code interpreter with custom execution role
761
+ code_interpreter = agentcore.CodeInterpreterCustom(self, "MyCodeInterpreter",
762
+ code_interpreter_custom_name="my_code_interpreter",
763
+ description="Code interpreter with custom execution role",
764
+ network_configuration=agentcore.CodeInterpreterNetworkConfiguration.using_public_network(),
765
+ execution_role=execution_role
766
+ )
767
+ ```
768
+
769
+ ### Code Interpreter IAM Permissions
770
+
771
+ The Code Interpreter construct provides convenient methods for granting IAM permissions:
772
+
773
+ ```python
774
+ # Create a code interpreter
775
+ code_interpreter = agentcore.CodeInterpreterCustom(self, "MyCodeInterpreter",
776
+ code_interpreter_custom_name="my_code_interpreter",
777
+ description="Code interpreter for Python execution",
778
+ network_configuration=agentcore.CodeInterpreterNetworkConfiguration.using_public_network()
779
+ )
780
+
781
+ # Create a role that needs access to the code interpreter
782
+ user_role = iam.Role(self, "UserRole",
783
+ assumed_by=iam.ServicePrincipal("lambda.amazonaws.com")
784
+ )
785
+
786
+ # Grant read permissions (Get and List actions)
787
+ code_interpreter.grant_read(user_role)
788
+
789
+ # Grant use permissions (Start, Invoke, Stop actions)
790
+ code_interpreter.grant_use(user_role)
791
+
792
+ # Grant specific custom permissions
793
+ code_interpreter.grant(user_role, "bedrock-agentcore:GetCodeInterpreterSession")
794
+ ```
795
+
796
+ ### Code interpreter with tags
797
+
798
+ ```python
799
+ # Create code interpreter with sandbox network mode (isolated)
800
+ code_interpreter = agentcore.CodeInterpreterCustom(self, "MyCodeInterpreter",
801
+ code_interpreter_custom_name="my_sandbox_interpreter",
802
+ description="Code interpreter with isolated network access",
803
+ network_configuration=agentcore.CodeInterpreterNetworkConfiguration.using_public_network(),
804
+ tags={
805
+ "Environment": "Production",
806
+ "Team": "AI/ML",
807
+ "Project": "AgentCore"
808
+ }
809
+ )
810
+ ```