POST /v1/agents/runtime/{runtime_id}/files/write
from gravixlayer import GravixLayer
client = GravixLayer() # defaults to cloud="aws", region="us-east-1"
sandbox = client.runtime.create() # defaults to template="base-small"
sandbox.file.write(
"/workspace/hello.txt",
"Hello from Gravix Layer\n",
)
# Read it back
result = sandbox.file.read("/workspace/hello.txt")
print(result.content)
sandbox.kill()
import { GravixLayer } from 'gravixlayer';
const client = new GravixLayer(); // defaults to cloud="aws", region="us-east-1"
const sandbox = await client.runtime.create(); // defaults to template="base-small"
await sandbox.file.write(
"/workspace/hello.txt",
"Hello from Gravix Layer\n",
);
// Read it back
const result = await sandbox.file.read("/workspace/hello.txt");
console.log(result.content);
await sandbox.kill();
gravixlayer runtime files write "$RT" /tmp/hello.txt 'hello'
curl -X POST "https://api.gravixlayer.ai/v1/agents/runtime/$RT/files/write" \
-H "Authorization: Bearer $GRAVIXLAYER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"path": "/tmp/hello.txt", "content": "hello"}'
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Yes | Destination file path |
content | string | Yes | File content |
Response
| Field | Type | Description |
|---|---|---|
message | string | Confirmation message |
path | string | Written file path |
bytes_written | integer | Number of bytes written |
Batch Write
Write multiple files in a single call (POST /v1/agents/runtime/{runtime_id}/files multipart):
from gravixlayer import GravixLayer, WriteEntry
client = GravixLayer() # defaults to cloud="aws", region="us-east-1"
sandbox = client.runtime.create() # defaults to template="base-small"
result = sandbox.file.write_many(
[
WriteEntry(path="/workspace/a.txt", data="File A\n"),
WriteEntry(path="/workspace/b.txt", data="File B\n"),
],
)
for f in result.files:
print(f.path, f.size)
sandbox.kill()
import { GravixLayer } from 'gravixlayer';
const client = new GravixLayer(); // defaults to cloud="aws", region="us-east-1"
const sandbox = await client.runtime.create(); // defaults to template="base-small"
const result = await sandbox.file.writeMany(
[
{ path: '/workspace/a.txt', data: 'File A\\n' },
{ path: '/workspace/b.txt', data: 'File B\\n' },
],
);
for (const f of result.files) {
console.log(f.path, f.size);
}
await sandbox.kill();
gravixlayer runtime files write-many "$RT" \
--file ./a.txt=/workspace/a.txt \
--file ./b.txt=/workspace/b.txt
curl -X POST "https://api.gravixlayer.ai/v1/agents/runtime/$RT/files" \
-H "Authorization: Bearer $GRAVIXLAYER_API_KEY" \
-F "file=@./a.txt;filename=/workspace/a.txt" \
-F "file=@./b.txt;filename=/workspace/b.txt"