live-code
Execute an example in an approved environment
| Field | Value |
|---|---|
| Trust class | connected |
| Implementation status | implemented_native |
| Renderer | native block |
| Key prop (production schema) | code |
| Key prop (protocol fixture) | code |
| Tools | run, cancel, reset |
| Package version | 1.0.0 |
| Package digest | sha256:337712c7adaa12651b91360682771ec891592494dad9678aceb296734bf90901 |
Install
docsloth component add @docsloth/live-code@1.0.0
Live package: sha256:337712c7adaa12651b91360682771ec891592494dad9678aceb296734bf90901 with 2 file digest(s); the catalog entry is generated from the built package, not a placeholder.
Props
The prop schema is normative in packages/contracts/component-props/live-code.schema.json.
| Prop | Type | Required | Constraints |
|---|---|---|---|
title | string | no | maxLength: 160 |
code | string | yes | maxLength: 200000 |
language | string | yes | maxLength: 40 |
filename | string | no | maxLength: 256 |
highlight_lines | array<integer> | no | |
files | array<object> | no | |
runtime | "browser-js" | "wasm-python" | "remote-sandbox" | yes | |
resource | object | no | additionalProperties: false |
resource.resource_id | string | yes | format: uuid |
resource.operation | string | yes | maxLength: 160 |
resource.environment | "test" | "staging" | "production" | yes | |
timeout_seconds | integer | yes | |
max_output_bytes | integer | yes |
Example props generated from this schema:
{
"title": "example-title",
"code": "echo hello",
"language": "example-language",
"filename": "example-filename",
"highlight_lines": [
1
],
"files": [
{
"path": "example-path",
"content": "example-content"
}
],
"runtime": "browser-js",
"resource": {
"resource_id": "00000000-0000-4000-8000-000000000000",
"operation": "example-operation",
"environment": "test"
},
"timeout_seconds": 1,
"max_output_bytes": 1
}
Required props: code, language, runtime, timeout_seconds, max_output_bytes.
Example
Example document IR (the block the renderer consumes):
{
"type": "live-code",
"props": {
"title": "example-title",
"code": "echo hello",
"language": "example-language",
"filename": "example-filename",
"highlight_lines": [
1
],
"files": [
{
"path": "example-path",
"content": "example-content"
}
],
"runtime": "browser-js",
"resource": {
"resource_id": "00000000-0000-4000-8000-000000000000",
"operation": "example-operation",
"environment": "test"
},
"timeout_seconds": 1,
"max_output_bytes": 1
}
}
Renderer HTML (entities decoded and wrapped for display):
<section class="ds-block ds-live-code" data-component="live-code" aria-labelledby="b-title">
<h3 class="ds-block-title" id="b-title">example-title</h3>
<p class="ds-code-caption">example-filename</p>
<pre class="ds-code" data-lang="example-language">
<code>echo hello</code>
</pre>
<p class="ds-code-caption">example-path</p>
<pre class="ds-code" data-lang="text">
<code>example-content</code>
</pre>
<dl class="ds-facts">
<div>
<dt>Runtime</dt>
<dd>
<code>browser-js</code>
</dd>
</div>
<div>
<dt>Time limit</dt>
<dd>1 s</dd>
</div>
<div>
<dt>Output limit</dt>
<dd>1 byte</dd>
</div>
<div>
<dt>Runs</dt>
<dd>
<code>example-operation</code> in the test environment</dd>
</div>
</dl>
<p class="ds-live-note" role="note">Running this example needs the live documentation site; the complete source is shown above.</p>
</section>
Preview (interface-only; the markup above is the same output):
example-title
example-filename
echo helloexample-path
example-content- Runtime
browser-js- Time limit
- 1 s
- Output limit
- 1 byte
- Runs
example-operationin the test environment
Running this example needs the live documentation site; the complete source is shown above.
The renderer resolves this component as a native block; the preview above is its real HTML output, and Markdown parity for native blocks is covered by the renderer test suite.
Specification
Generated from packages/contracts/component-specs/live-code.md.
Contract
Production props are normative in ../contracts/component-props/live-code.schema.json. The corresponding component-fixtures manifest is only a minimal protocol fixture; use the production props schema when building the published package. The packaged artifact ships exactly its generated component-package.json manifest plus props.schema.json (the production props schema, copied byte-for-byte) and spec.md (this spec, copied byte-for-byte); it contains no executable payload, fallback implementation, Storybook, test suite, SSR harness or README. Rendering behavior and the acceptance cases below belong to the renderer and the repository tests, not to the package. Installation pins the package version and the digest of every shipped byte.
Intended behavior
Runs only in isolated executor, explicit run click/authorized tool; session teardown, output limits and version-pinned dependencies.
Failure and fallback
Budget/permission failure leaves code readable and Copy available.
Required acceptance cases
Infinite loop cancelled; attempted network/key read denied; deterministic result when test fixture used. Also test empty data, loading, denied access, browser without JS, mobile 360px, keyboard navigation, dark mode and an explicit constrained agent tool call. The server independently authorizes capability requests; a package manifest cannot grant authority.
Data and maintenance
Data bindings resolve from a specific publication/release vector and permitted fact/evidence graph. Configuration edits create versioned component patches. Update invalidation uses dependency IDs, never indiscriminate whole-page regeneration. Human-owned props survive automatic updates unless invalidated with an explicit conflict. Missing optional resources leave an honest inert/readable fallback, not a broken page or fake success.
Cost and tools
Pure/local interaction must never invoke a model by accident. Any model, remote query or executor call must reserve approved budget before dispatch. Public visitors do not inherit owner resources. The component may call only named tools in its signed manifest with valid typed inputs. A cancelled job stops polling and closes resources. No component gets platform administration, raw credentials or an unlimited execution loop.
Package manifest
Protocol fixture: packages/contracts/component-fixtures/live-code.json.
| Field | Value |
|---|---|
| Name | @docsloth/live-code |
| Version | 1.0.0 |
| Protocol | 1.x |
| License | Apache-2.0 |
| Runtime | react |
| Entry | dist/index.js |
| Recording policy | blocked |
| Fallback | html, markdown, json |
| Network hosts | none |
| Production write | no |
| Max runtime seconds | 120 |
| Integrity | all zeros (protocol fixture placeholder) |
| Tool | Effect | Confirmation | Input |
|---|---|---|---|
| run | execute | no | value |
| cancel | read | no | value |
| reset | local_write | no | value |
Sources
| Source | Path |
|---|---|
| Component page | https://registry.docsloth.dev/components/live-code.html |
| Markdown twin | https://registry.docsloth.dev/docs/live-code.md |
| LLM index | https://registry.docsloth.dev/llms.txt |
| Specification | packages/contracts/component-specs/live-code.md |
| Prop schema | packages/contracts/component-props/live-code.schema.json |
| Protocol fixture | packages/contracts/component-fixtures/live-code.json |
| Catalog | packages/contracts/component-catalog.json |