Implementation:Openai Openai node Containers Resource
| Knowledge Sources | |
|---|---|
| Domains | SDK, Containers |
| Last Updated | 2026-02-15 12:00 GMT |
Overview
The Containers class is the Containers resource in the openai-node SDK, providing methods to create, retrieve, list, and delete sandbox containers used for code execution environments.
Description
The Containers class extends APIResource and wraps the /containers REST endpoints. It is accessed via client.containers and provides standard CRUD operations for managing sandbox containers. Each container has a name, status, optional memory limit (1g, 4g, 16g, or 64g), optional expiration policy, and a network access policy.
The resource provides four methods: create for creating a new container with a name and optional configuration, retrieve for fetching a container by ID, list for paginating containers with optional name and order filters, and delete for removing a container. The create method supports specifying file_ids to copy files into the container, expires_after with an anchor-based expiration strategy, memory_limit, network_policy (allowlist with specific domains, or disabled), and skills.
The resource also exposes a files sub-resource (of type Files) for managing files within containers. Container responses include fields for id, created_at, name, object, status, expires_after, last_active_at, memory_limit, and network_policy.
Usage
Use this resource when you need to create and manage sandbox containers for code execution environments, such as when using tools that require isolated execution contexts.
Code Reference
Source Location
- Repository: openai-node
- File: src/resources/containers/containers.ts
Signature
export class Containers extends APIResource {
files: FilesAPI.Files;
create(body: ContainerCreateParams, options?: RequestOptions): APIPromise<ContainerCreateResponse>;
retrieve(containerID: string, options?: RequestOptions): APIPromise<ContainerRetrieveResponse>;
list(
query?: ContainerListParams | null,
options?: RequestOptions,
): PagePromise<ContainerListResponsesPage, ContainerListResponse>;
delete(containerID: string, options?: RequestOptions): APIPromise<void>;
}
Import
import OpenAI from 'openai';
// Access via client.containers
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | string |
Yes | Name of the container to create |
| file_ids | Array<string> |
No | IDs of files to copy into the container |
| expires_after | { anchor: 'last_active_at'; minutes: number } |
No | Container expiration time relative to the anchor |
| memory_limit | '4g' | '16g' | '64g' | No | Memory limit for the container (defaults to '1g') |
| network_policy | ContainerNetworkPolicyAllowlist | No | Network access policy for the container |
| skills | InlineSkill> | No | Optional list of skills referenced by id or inline data |
| containerID (retrieve/delete) | string |
Yes | The ID of the container to retrieve or delete |
| query (list) | ContainerListParams |
No | Pagination params, optional name filter and sort order |
Outputs
| Name | Type | Description |
|---|---|---|
| ContainerCreateResponse | ContainerCreateResponse |
Created container with id, created_at, name, object, status, expires_after, last_active_at, memory_limit, network_policy |
| ContainerRetrieveResponse | ContainerRetrieveResponse |
Retrieved container with same fields as create response |
| ContainerListResponse | ContainerListResponse |
Paginated list item with same fields as create response |
| void | void |
Delete returns no body |
Usage Examples
import OpenAI from 'openai';
const client = new OpenAI();
// Create a container
const container = await client.containers.create({
name: 'my-sandbox',
memory_limit: '4g',
expires_after: {
anchor: 'last_active_at',
minutes: 60,
},
});
console.log(container.id);
// Retrieve a container
const retrieved = await client.containers.retrieve(container.id);
console.log(retrieved.status);
// List containers
for await (const c of client.containers.list({ order: 'desc' })) {
console.log(c.name, c.status);
}
// Delete a container
await client.containers.delete(container.id);